[Tex/LaTex] How to fix the width of a minipage

boxesminipagepositioning

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.

Best Answer

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}​​​​​​​

Pictures framed inside minipages

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}

Vertical line separating pictures

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.