I have arranged within approx. 20 minipages a data plot, several pictures with attached labels taking columnwidth, columnsep of the twocolumn paper format etc into account.
For debugging purposes, I have surrounded each minipage with a \cfbox
command to see the width and height of the minipages, unintended whitespace, proper alignment w.r.t. each other.
Update:
The resulting pdf-document looks like this:
The source code is:
\documentclass[class=elsarticle,preprint,5p,10pt,twocolumn]{standalone}
\usepackage{mwe}
\usepackage{calc}
\usepackage{xcolor}
\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0.001pt}
\newcommand{\cfbox}[1]{%
\colorlet{currentcolor}{.}%
{\color{red}%
\fbox{\color{currentcolor}#1}}%
}
\newlength{\mywidth}
\setlength{\mywidth}{3.2in}
\newlength{\myheight}
\setlength{\myheight}{3.2in}
\begin{document}
\cfbox{\begin{minipage}[t][\myheight][b]{\mywidth}
\cfbox{\includegraphics[width=\mywidth, height=\myheight]{plot}}
\end{minipage}}%
\cfbox{\begin{minipage}[t][\myheight][c]{\mywidth} % currently square (not necessarily)
\cfbox{\begin{minipage}[t][\myheight*\real{0.125}][b]{\textwidth} % gnuplot tmargin
\centering
Series 1\vspace{\lineskip}
\end{minipage}}\\[-\lineskip]
\cfbox{\begin{minipage}[t][\myheight*\real{0.75}/\real{3}]{\textwidth}
\cfbox{\begin{minipage}{\textwidth/\real{2}}
\centering
\cfbox{\includegraphics[width=0.4\textwidth]{example-image-a}}
\scriptsize{}label-a
\end{minipage}}%
\cfbox{\begin{minipage}{\textwidth/\real{2}}
\centering
\cfbox{\includegraphics[width=0.4\textwidth]{example-image-b}}
\scriptsize{}label-b
\end{minipage}}%
\end{minipage}}\\[-\lineskip]
\cfbox{\begin{minipage}[t][\myheight*\real{0.75}/\real{3}][c]{\textwidth}
\centering
Series 2\vspace{\lineskip}
\cfbox{\begin{minipage}{\textwidth/\real{2}}
\centering
\cfbox{\includegraphics[width=0.4\textwidth]{example-image-a}}
\scriptsize{}label-a
\end{minipage}}%
\cfbox{\begin{minipage}{\textwidth/\real{2}}
\centering
\cfbox{\includegraphics[width=0.4\textwidth]{example-image-b}}
\scriptsize{}label-b
\end{minipage}}%
\end{minipage}}\\[-\lineskip]
\cfbox{\begin{minipage}[t][\myheight*\real{0.75}/\real{3}]{\textwidth}
\vfill
\centering
Series 3\vspace{\lineskip}
\cfbox{\begin{minipage}{\textwidth/\real{2}}
\centering
\cfbox{\includegraphics[width=0.4\textwidth]{example-image-a}}
\end{minipage}}%
\cfbox{\begin{minipage}{\textwidth/\real{2}}
\centering
\cfbox{\includegraphics[width=0.4\textwidth]{example-image-b}}
\end{minipage}}%
\end{minipage}}\\[-\lineskip]
\cfbox{\begin{minipage}[t][\myheight*\real{0.125}]{\textwidth} % gnuplot bmargin
\vspace{\lineskip}
\cfbox{\begin{minipage}{\textwidth/\real{2}}
\centering
\scriptsize{}label-a
\end{minipage}}%
\cfbox{\begin{minipage}{\textwidth/\real{2}}
\centering
\scriptsize{}label-b
\end{minipage}}%
\end{minipage}}
\end{minipage}}%
\end{document}
I consider this source code as messy.
I'd like to remove the debugging code from the body of the document, i.e. remove the \cfbox
within \begin{document}
and \end{document}
, and re-define the minipage command in the preamble.
However, I could not find a solution adding colored boxes to minipages without introducing additional whitespace.
I have considered:
- package
framed
- package
boxedminipage
- renewenvironment
minipage
withxparse
I hope the update explains that the visible borders are meant to be only temporary. They are not in the final document. Currently, I remove them by redefining \cfbox
by \renewcommand{\cfbox}[1]{#1}
Partially working solution based on the answer by @touhami and @egreg's answer on renew minipage with xparse
\documentclass{article}
\usepackage{xcolor}
\usepackage{xparse}
\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0.0001pt}
\setlength{\parindent}{0pt}
\newbox\mtbox
\let\latexminipage\minipage
\let\latexendminipage\endminipage
\colorlet{currentcolor}{.}
\RenewDocumentEnvironment{minipage}{ooom}
{%
\IfNoValueTF{#1}
{\setbox\mtbox\vbox\bgroup\hsize=#4
\latexminipage{\hsize}}
{%
\IfNoValueTF{#2}
{\setbox\mtbox\vbox\bgroup\hsize=#4
\latexminipage[#1]{#4}}
{%
\IfNoValueTF{#3}
{\setbox\mtbox\vbox\bgroup\hsize=#4
\latexminipage[#1][#2]{#4}}
{\setbox\mtbox\vbox\bgroup\hsize=#4
\latexminipage[#1][#2][#3]{#4}}%
}%
}%
}
{\latexendminipage\egroup%
\color{red}\fbox{\color{currentcolor}\box\mtbox}}
\newcommand{\mylipsum}{Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
adipiscing vitae, felis.}
\begin{document}
\begin{minipage}[t][1in]{5cm}
\mylipsum
\end{minipage}
\end{document}
However, setting a minipage width or height by \begin{minipage}[t][\myheight*\real{0.75}/\real{3}]{\textwidth}
, a wrong measure is applied. This has probably something to do with the xparse
package based redefinition of the minipage environment. Answer by egreg does not have this issue.
Best Answer
My impression is that you're overcomplicating things.
When you have finished debugging, just redefine
\cbox
to do nothing:If you don't want
\cbox
in the way, you can redefineminipage
and\includegraphics
to do it implicitly:If you have other constructions that should have an implicit frame, you have to cope with them separately in a similar fashion.