10

I would like to set a color to the leftmost minipage in the following code:

\usepackage{xcolor}
\fcolorbox{red}{gray}{
  \begin{minipage}{0.33\textwidth}
  some text
  \end{minipage}
}

\begin{minipage}{0.67\textwidth}
some other text
\end{minipage}

but the leftmost minipage is displayed over the whole page and the rightmost appears on the second page (given there is enough text in both). I read that one should set innerleftmargin, innerrightmargin and paragraph parameters to 0, but that didn't work either. What is the right way to do it?

4

You need to take into account \fboxsep (the horizontal length between the frame and the contents) and \fboxrule (the thickness of the rules used by the frame); since the length \fboxsep is applied to the left and right, you need to subtract two of those lengths, as well as two \fboxrules. Also, remove spurious blank spaces (a change of line in the code is tantamount to one space) from your code and blank lines (a blank line in the code ends the previous paragraph, so your second minipage starts a new paragraph). Using e-TeX's \dimexpr you can perform basic arithmetics with lengths:

\documentclass{article}
\usepackage{xcolor}

\begin{document}

\noindent\fcolorbox{red}{gray}{%
\begin{minipage}{\dimexpr0.33\textwidth-2\fboxrule-2\fboxsep\relax}
some text
\end{minipage}}%
\begin{minipage}{0.67\textwidth}
some other text
\end{minipage}

\end{document}
| improve this answer | |
  • that almost worked, i was using a custom document style which i can't post here unfortunately. but the problem was fixed after what you suggested and also changing the horizontal spacing in the following command: \usepackage[hmargin=0.75cm, vmargin=0.75cm]{geometry} – iggy Aug 13 '14 at 20:26

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.