3

I am using two minipages. If I use colors, the top rows do not align. Why is that? Here is a MWE:

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


\begin{minipage}[t]{0.45\textwidth}
{Without colors, the second column aligns nicely with the top row of the first. 
} 
\end{minipage}%
\hfill
\begin{minipage}[t]{0.45\textwidth}
{
Nice alignment.
}
\end{minipage}

\vspace*{1cm}

\begin{minipage}[t]{0.45\textwidth}
{With colors, however, the second column does not align with the top row of the first.
} 
\end{minipage}%
\hfill
\begin{minipage}[t]{0.45\textwidth}
{
{\color{green}Problem...}
}
\end{minipage}

\end{document}
4

It's because colors are whatsits and adding a color in vertical mode is somehow difficult. Inserting whatsits isn't transparent in any case:

\documentclass{article}
\begin{document}

\begin{minipage}[t]{0.45\textwidth}
{Without colors, the second column aligns nicely with the top row of the first.}% 
\end{minipage}%
\hfill
\begin{minipage}[t]{0.45\textwidth}
{\special{}Nice alignment.}%
\end{minipage}

\end{document}

You can add \leavevmode before \color to change the color in the horizontal mode:

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


\begin{minipage}[t]{0.45\textwidth}
{Without colors, the second column aligns nicely with the top row of the first.}% 
\end{minipage}%
\hfill
\begin{minipage}[t]{0.45\textwidth}
{Nice alignment.}%
\end{minipage}

\vspace*{1cm}

\begin{minipage}[t]{0.45\textwidth}
{With colors, however, the second column does not align with the top row of the first.}%
\end{minipage}%
\hfill
\begin{minipage}[t]{0.45\textwidth}
{{\leavevmode\color{green}Problem...}}%
\end{minipage}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.