使用 fbox 格式的小页面,fboxsep=0pt,fboxrule=0.0001pt,并带有彩色边框

使用 fbox 格式的小页面,fboxsep=0pt,fboxrule=0.0001pt,并带有彩色边框

我在大约 20 个小页内安排了一个数据图、几张带有附加标签的图片,其中考虑了双列纸张格式的列宽、列间距等。

为了调试目的,我用\cfbox命令包围了每个小页面,以查看小页面的宽度和高度、非预期的空白以及彼此之间的正确对齐。

更新

生成的 pdf 文档如下所示:

在此处输入图片描述

源代码是:

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

我认为这个源代码很混乱。

我想从文档主体中删除调试代码,即删除和\cfbox内的,并在序言中重新定义 minipage 命令。\begin{document}\end{document}

但是,我找不到在不引入额外空白的情况下向小页面添加彩色框的解决方案。

我考虑过:

  • 包裹framed
  • 包裹boxedminipage
  • 更新minipage环境xparse

我希望更新说明可见边框只是暂时的。它们不在最终文档中。目前,我通过重新定义来删除\cfbox它们\renewcommand{\cfbox}[1]{#1}

根据以下答案部分有效的解决方案@touhami@egreg 关于使用 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}

但是,将 minipage 宽度或高度设置为 时,会应用错误的测量值。这可能与基于包的 minipage 环境的重新定义\begin{minipage}[t][\myheight*\real{0.75}/\real{3}]{\textwidth}有关。xparseegreg 的回答不存在这个问题

答案1

我的印象是你把事情复杂化了。

\documentclass{article}
\usepackage{graphicx,xcolor}

\newsavebox{\cfboxbox}
\newcommand{\cfbox}[1]{%
  \mbox{%
    \sbox{\cfboxbox}{#1}%
    \setlength{\fboxsep}{-0.0001pt}% don't add space
    \setlength{\fboxrule}{0.0001pt}%
    \color{red}%
    \fbox{\usebox{\cfboxbox}}%
  }%
}

\begin{document}

\cfbox{\includegraphics[width=3cm]{example-image}}

\cfbox{\textcolor{blue}{Hello world}}

\end{document}

在此处输入图片描述

调试完成后,只需重新定义\cbox即可不执行任何操作:

\newcommand{\cbox}[1]{#1}

如果您不想\cbox妨碍,您可以重新定义minipage\includegraphics隐式地执行此操作:

\documentclass{article}
\usepackage{graphicx,xcolor,calc}


\let\latexminipage\minipage
\let\endlatexminipage\endminipage
\let\latexincludegraphics\includegraphics

\newsavebox{\cfboxbox}

\newcommand{\redbox}[1]{%
  \mbox{%
    \setlength{\fboxsep}{-0.0001pt}%
    \setlength{\fboxrule}{0.0001pt}%
    \color{red}%
    \fbox{#1}%
  }%
}

\renewenvironment{minipage}
 {\begin{lrbox}{\cfboxbox}\begin{latexminipage}}
 {\end{latexminipage}\end{lrbox}\redbox{\usebox{\cfboxbox}}}

\renewcommand{\includegraphics}[2][]{%
  \redbox{\latexincludegraphics[#1]{#2}}%
}

\newlength{\mywidth}
\setlength{\mywidth}{2in}
\newlength{\myheight}
\setlength{\myheight}{2in}

\begin{document}

\begin{minipage}[t][\myheight][b]{\mywidth}
  \includegraphics[width=\mywidth, height=\myheight]{example-image}
\end{minipage}%
\begin{minipage}[t][\myheight][c]{\mywidth} % currently square (not necessarily)
  \begin{minipage}[t][\myheight*\real{0.125}][b]{\textwidth} % gnuplot tmargin
    \centering
    Series 1\vspace{\lineskip}
  \end{minipage}\\[-\lineskip]
  \begin{minipage}[t][\myheight*\real{0.75}/\real{3}]{\textwidth}
    \begin{minipage}{\textwidth/\real{2}}
      \centering
      \includegraphics[width=0.4\textwidth]{example-image-a}

      \scriptsize{}label-a
    \end{minipage}%
    \begin{minipage}{\textwidth/\real{2}}
      \centering
      \includegraphics[width=0.4\textwidth]{example-image-b}

      \scriptsize{}label-b
    \end{minipage}%
  \end{minipage}
\end{minipage}

\end{document}

在此处输入图片描述

如果您有其他应该具有隐式框架的构造,则必须以类似的方式分别处理它们。

答案2

像这样 在此处输入图片描述

\documentclass{article}
\usepackage{xcolor,graphicx}

\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0.0001pt}
\setlength{\parindent}{0pt}

\newbox\mtbox
\newenvironment{myminipage}[1]%
{\setbox\mtbox\vbox\bgroup\hsize=#1
\begin{minipage}{\hsize}}%
{\end{minipage}\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}

\colorlet{currentcolor}{.}
\begin{myminipage}{5cm}
\mylipsum
\end{myminipage}

\mylipsum

\begin{myminipage}{\columnwidth}
\includegraphics{example-image}
\end{myminipage}

\end{document}

相关内容