# parbox vertical alignment

The following code uses parboxes and hrules to vertically align two rectangles of different heights. The hrule seem a bit hackish to me. Is there a more elegant solution?

\documentclass{article}
\begin{document}
\begin{minipage}[t]{4in}
\parbox[t]{2cm}{\hrule height 0pt width 0pt \rule{1cm}{1cm}}
\parbox[t]{2cm}{\hrule height 0pt width 0pt \rule{1cm}{3cm}}
\end{minipage}
\end{document}


My apologies. I tried to simplify the problem and only obfuscated it. The real problem is vertical alignment of two figures, each created in separate Tikz environments. I would like the y's to be at the same height, but I'd like to accomplish this outside of tikz.

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\draw (0,0)--(0,1) node[above]{$y$};
\end{tikzpicture}

\begin{tikzpicture}
\draw (0,0)--(0,3) node[above]{$y$};
\end{tikzpicture}

\end{document}

• Do you want to align black boxes or other objects? – egreg Oct 13 '13 at 22:37
• Why don't you post your tikz code directly? – user11232 Oct 14 '13 at 0:02
• Still it is not clear. Do you have two tikzpicutres? I it is only one try with \draw (0,0)--(0,1) node[above]{$y$}; \draw (1,-2)--(1,1) node[above]{$y$}; – user11232 Oct 14 '13 at 1:30
• @HarishKumar Please see my edited comment above - there are two tikzpictures. The solution by Steven B. Segletes using the stackengine package is appreciated. Do you have a solution that does not require additional packages? – steven_nevets Oct 14 '13 at 4:08
• @steven_nevets: I feel that setting the baselines within the tikzpicture is more elegant. However you can use \parbox[t]{2cm}{\null \begin{tikzpicture}...} for both pictures. – user11232 Oct 14 '13 at 4:26

\documentclass{article}
\begin{document}

\begin{minipage}[t]{4in}
\parbox[t]{2cm}{\rule[-1cm]{1cm}{1cm}}
\parbox[t]{2cm}{\rule[-3cm]{1cm}{3cm}}
\end{minipage}

or simpler

\begin{minipage}[t]{4in}
\rule[-1cm]{1cm}{1cm}\hspace{1cm}%
\rule[-3cm]{1cm}{3cm}
\end{minipage}

\end{document}

• That's a good question. I actually want to align tikz figures whose heights are not readily identified. Unfortunately, that renders the negative vertical compensations unhelpful. Any advise? – steven_nevets Oct 13 '13 at 23:59
• @steven_nevets For something like Tikz don't you always know the height? As always, it really helps if you post a complete document that demonstrates the real problem. – David Carlisle Oct 14 '13 at 0:06

Just name the two nodes:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[baseline=(T1.base)]
\draw (0,0)--(0,1) node[above](T1){$y$};
\end{tikzpicture}
\begin{tikzpicture}[baseline=(T2.base)]
\draw (0,0)--(0,3) node[above](T2){$y$};
\end{tikzpicture}

\end{document}


\documentclass{article}
\usepackage{tikz}
\usepackage{stackengine}
\begin{document}

\belowbaseline[0pt]{%
\begin{tikzpicture}
\draw (0,0)--(0,1) node[above]{$y$};
\end{tikzpicture}
}
\belowbaseline[0pt]{%
\begin{tikzpicture}
\draw (0,0)--(0,3) node[above]{$y$};
\end{tikzpicture}
}
\end{document}