# How to fix the width of a minipage?

I put 2 minipages containing tikzpicture side by side: one on the left, the other one on the right. And I hope each minipage, surrounded by \fbox, occupies almost half side of the page, and leave some little space between them. I also want each minipage to have a caption and label. So now I could think of the following code:

\begin{minipage}[t]{0.48\linewidth}%
\centering
\fbox{
\begin{minipage}[t]{0.48\linewidth}
picture1
\end{minipage}}
\captionof{figure}{picture1}\label{fig:picture1}
\end{minipage}\hfill

\begin{minipage}[t]{0.48\linewidth}%
\centering
\fbox{
\begin{minipage}[t]{0.48\linewidth}
picture2
\end{minipage}}
\captionof{figure}{picture2}\label{fig:picture2}
\end{minipage}


However, the problem is the width of the frame or minipage is up to the width of the picture. I would like to fix that width, let's say around 0.48\linewidth, but it seems that \begin{minipage}[t]{0.48\linewidth}% could not do that.

-

The problem occurs because of the subtle length-management when using a minipage within a minipage. The outer minipage of width 0.48\linewidth sets the line width within that minipage to 0.48\linewidth. If the inner minipage is set to a width of 0.48\linewidth, it is actually 0.2304 of the original \linewidth, since the nested minipage compounds the lengths. You also need to remove the spurious space after \fbox{ by using %. Using this is better:

\documentclass{article}
\usepackage{caption,subcaption}%
\usepackage{calc}% http://ctan.org/pkg/calc
\usepackage[showframe]{geometry}% http://ctan.org/pkg/geometry

​\begin{document}
\noindent\begin{minipage}[t]{0.48\linewidth}%
\centering
\fbox{%
\begin{minipage}[t]{\linewidth-2\fboxsep-2\fboxrule}% Remove fbox rule/sep width
picture1
\end{minipage}}
\captionof{figure}{picture1}\label{fig:picture1}
\end{minipage}\hfill
\begin{minipage}[t]{0.48\linewidth}%
\centering
\fbox{%
\begin{minipage}[t]{\linewidth-2\fboxsep-2\fboxrule}% Remove fbox rule/sep width
picture2
\end{minipage}}
\captionof{figure}{picture2}\label{fig:picture2}
\end{minipage}
​\end{document}​​​​​​​


If you're interested in a vertical divider between the two images to visually separate them from one another, one could typeset the entire structure inside a multicols environment:

\documentclass{article}
\usepackage{caption,subcaption}%
\usepackage{calc}% http://ctan.org/pkg/calc
\usepackage{multicol}% http://ctan.org/pkg/multicol
\usepackage{lipsum}% http://ctan.org/pkg/lipsum

\begin{document}
\lipsum[1]

\renewcommand{\columnseprule}{0.4pt}% Columns are separated by rule of width 0.4pt
\begin{multicols}{2}% Two-column layout
\setlength{\parindent}{0pt}% No paragraph indent
\begin{minipage}[t]{\linewidth}%
\fbox{%
\begin{minipage}[t]{\linewidth-2\fboxsep-2\fboxrule}% Remove fbox rule/sep width
picture1
\end{minipage}}
\captionof{figure}{picture1}\label{fig:picture1}
\end{minipage}

\begin{minipage}[t]{\linewidth}%
\fbox{%
\begin{minipage}[t]{\linewidth-2\fboxsep-2\fboxrule}% Remove fbox rule/sep width
picture2
\end{minipage}}
\captionof{figure}{picture2}\label{fig:picture2}
\end{minipage}
\end{multicols}

\lipsum[2]
\end{document}


The use of the calc package is merely for calculation of lengths. And, the geometry package is used to highlight the page frame. Also, the lipsum package provides some dummy text.

-
Thanks for your comment, i just run your code itself, why does it return 2 lines on the top of the page and 1 line on the bottom of the page? –  SoftTimur Aug 16 '11 at 23:26
OK, I see, it is the showframe... –  SoftTimur Aug 16 '11 at 23:27
@SoftTimur: Yes, this is the geometry package output when specifying the option showframe. It includes lines that distinguish between the header, footer, margin, etc. –  Werner Aug 16 '11 at 23:29
By the way, what if I want to add a vertical line between these 2 pictures, just to show a separation. I have seen somebody doing it, but do not know how they realized that... –  SoftTimur Aug 16 '11 at 23:43
Just between the images, or also spanning to between the figure captions? –  Werner Aug 16 '11 at 23:48