# How do lines of \framebox'es line up?

I want to stack boxes. The frame lines of the boxes should be exactly on top of each other.

## The original question

However, when I define two boxes, so that one starts where the other ends (spatially speaking), the lines do not overlap and I get a fat line, because of two thin lines next to each other. I have to move one box a little bit, so that it works the way I want it. See the MWE below.

\documentclass[a4paper, 12pt, titlepage]{article}

\begin{document}

\setlength{\unitlength}{1cm}
\begin{picture}(6.6, 3.1)

\put(0.2,1.4){\framebox(2.4, 1){\shortstack{my bottom \\ is fat}}}
\put(0.2,0.7){\framebox(2.4, 0.7){}}

\end{picture}

\begin{picture}(6.6, 3.1)

\put(0.2,1.41){\framebox(2.4, 1){\shortstack{my bottom \\ is not fat}}}
\put(0.2,0.7){\framebox(2.4, 0.7){}}

\end{picture}

\end{document}


But this "solution" is horrible, because if the line thickness is changed, it falls apart. Is there a way to say that the middle of the line should be the exactly on the edge of the box?

## Wait, there's more

So that M in MWE stands for minimal, right? So why bother including all those parameters for the document class that shouldn't matter here anyway. So in comparison to the first one this second MWE, the truly MWE, has no optional parameters for the document class:

\documentclass{article}

\begin{document}

\setlength{\unitlength}{1cm}
\begin{picture}(6.6, 3.1)

\put(0.2,1.4){\framebox(2.4, 1){\shortstack{my bottom \\ is fat}}}
\put(0.2,0.7){\framebox(2.4, 0.7){}}

\end{picture}

\begin{picture}(6.6, 3.1)

\put(0.2,1.41){\framebox(2.4, 1){\shortstack{my bottom \\ is not fat}}}
\put(0.2,0.7){\framebox(2.4, 0.7){}}

\end{picture}

\end{document}


To my surprise, this caused a bit of a swap in terms of fatness:

What's going on here? Under what conditions do the lines line up? What influences this? How can I make a prediction of what the picture will look like? When do I have to correct the position of the box and when not?

• This is not the Monty Hall, but the Shallow Hal problem. – null Jun 20 '15 at 17:20
• The frame is drawn “inside” the box. You should use \makebox and draw the borders with \line. I see no change in the two cases, what you seem to see is probably due to snapping of pixels to the grid at low resolution. – egreg Jun 20 '15 at 17:45
• @egreg that sounds tedious, but looks like a valid workaround. Any idea on why it changes with different document class parameters? – null Jun 20 '15 at 17:48
• As I said, it doesn't change. Apart from the size of characters, I get the same result in both cases: the top picture has a fatter mid line than the bottom one. – egreg Jun 20 '15 at 17:50
• @egreg If they are drawn "inside", why does moving the top box up solve the problem then? Doesn't this solution suggest that they are drawn "outside of the box"? – null Jun 20 '15 at 17:54

If only two boxes need to be stacked, tcolorbox can be used. By default all tcolorboxes have upper and lower parts.

\documentclass{article}
\usepackage[most]{tcolorbox}

\tcbset{nobeforeafter}

\newtcolorbox{mybox}[1][]{
enhanced,
notitle,
colframe=black,
colback=white,
segmentation style={solid,line width=0.5mm},
sharp corners,
width=3cm,
split=0.5,
#1}

\begin{document}

\begin{mybox}
Upper part
\tcblower
Lower part
\end{mybox}
\begin{mybox}[height=4cm, valign=center]
Upper part
\tcblower
Lower part
\end{mybox}
\begin{mybox}[height=6cm, width=4cm, halign=center, valign lower=bottom]
Upper part
\tcblower
Lower part
\end{mybox}

\end{document}


If more than two boxes are necessary, a possible solution could be a TiKZ splited rectangle, although in this case is more difficult to control empty parts height.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart, positioning}

\begin{document}

\begin{tikzpicture}

\node[rectangle split, rectangle split parts=2, draw, text width=2cm, align=center] (a) {Upper\nodepart{two}Lower};

\node[rectangle split, rectangle split parts=3, draw, text width=2cm, align=center, right = of a] (b) {Upper\nodepart{two}\rule{0pt}{2cm}\nodepart{three}};

\node[rectangle split, rectangle split parts=5, draw, text width=2cm, align=center, right=of b] (c) {Upper};

\end{tikzpicture}

\end{document}