# Align the top of a TikZ picture with the text

Usually the bottom of a tikzpicture is aligned with the baseline of the text. If you want to change that, you can use the option baseline on the picture. This lets the bottom of the tikzpicture be 5 ex below the baseline of the text:

\begin{tikzpicture}[baseline=-5ex]
\draw [red, very thick, dashed] (1,0) -- (0,0) -- (0,1);
\end{tikzpicture}


Instead of manually calculating the height of the drawing you want to include, you can use the provided current bounding box which is the rectangle containing all of the elements in the picture. This is a node with the usual anchors, i.e., north, south, east, west. To align the top of the box with the baseline of the text, use the following (note the parentheses, it’s a reference to a node!):

\begin{tikzpicture}[baseline=(current bounding box.north)]
...


Now probably you don’t want to align your picture with the baseline but with the top of the text. You can play around with the tikzpicture baseline further by introducing a yshift. For example a lowercase x is 1 ex high, so to align the top of the tikzpicture with the top of a lowercase x use a yshift of 1 ex (for uppercase letters or t, f, etc. try 1.6 ex). Be careful to copy all the different {( and [!:

\begin{tikzpicture}[baseline={([yshift={-1ex}]current bounding box.north)}]
...


# Set height of a minipage

The width of a minipage is a mandatory parameter. But hidden in the optional parameters is a way to set a specific height for a minipage.

The first parameter is the position of the minipage relative to the baseline. Possible values are ‘t’ (top of the minipage is level with the line), ‘c’ (center of the minipage is level with the line) or ‘b’ (bottom of the minipage is level with the line).

The second parameter is the height. The minipage will have exactly this height. If the text inside the minipage is longer, it will spill out of the box, the height is not adjusted. If the text is shorter, the remainder of the box will be empty.

The last parameter is the vertical position of the text inside the minibox. Possible values are ‘t’ (top-aligned), ‘c’ (centered), and ‘b’ (bottom-aligned).

\begin{minipage}[t][5cm][t]{0.5\textwidth}
test
\end{minipage}