如何仅在框架框中设置水平分隔?

如何仅在框架框中设置水平分隔?

我正在使用命令\fcolorbox在图像周围添加一个框架框。我只想设置水平分隔。\fboxsep我设置了四周的分隔。

\documentclass[oneside]{article}

\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{xcolor}

\definecolor{light-gray}{gray}{0.75}
\setlength{\fboxsep}{2pt}

\begin{document}
  \begin{minipage}{0.5\linewidth}
    \fcolorbox{light-gray}{white}{\includegraphics[trim=0mm 2mm 0mm 2mm, clip=true, scale=1]{../figures/fig.pdf}}
  \end{minipage}
\end{document}

答案1

\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\newcommand\FBox[3][1ex]{{% default space is 1ex
    \color{light-gray}\frame{\hspace{#1}\includegraphics[#2]{#3}\hspace{#1}}}}
\definecolor{light-gray}{gray}{0.75}

\begin{document}
\frame{\includegraphics[width=4cm]{tiger}}% without space

\FBox[2em]{width=4cm}{tiger}% horizontal space is 2em

\FBox{width=4cm}{tiger}% now the default of 1ex     
\end{document} 

enter image description here

如果您正在使用该类,beamer则将命令修改为:

\let\myFrame\frame
\documentclass{beamer}
\newcommand\FBox[3][1ex]{{% default space is 1ex
        \color{light-gray}\myFrame{\hspace{#1}\includegraphics[#2]{#3}\hspace{#1}}}}
\definecolor{light-gray}{gray}{0.75}
...

答案2

这是一个简单的解决方案,使用一个myfcolorbox命令,其中一个可选参数,即框架和内容之间的水平距离:

\documentclass[oneside]{article}

\usepackage[demo]{graphicx}
\usepackage{epstopdf}
\usepackage{xcolor}

\definecolor{light-gray}{gray}{0.75}
\setlength{\fboxsep}{0pt}

\begin{document}

  \begin{minipage}{0.5\linewidth}
    \fcolorbox{light-gray}{white}{\hskip0.5em\includegraphics[trim=0mm 2mm 0mm 2mm, clip=true, scale=1]{../figures/fig.pdf}\hskip0.5em}
  \end{minipage}

\end{document} 

enter image description here

答案3

下面的宏\hfcolorbox具有与相同的语法,但仅在内容的左侧和右侧\fcolorbox添加。\fboxsep

的设置\hfcolorboxsep是在最后一刻设置的,因此它将使用 的当前值\fboxsep

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

\newlength{\hfcolorboxsep}

\NewDocumentCommand{\hfcolorbox}{ommm}{%
  \begingroup
  \setlength{\hfcolorboxsep}{\fboxsep}%
  \setlength{\fboxsep}{0pt}%
  \IfNoValueTF{#1}
   {\fcolorbox{#2}{#3}{\hspace{\hfcolorboxsep}#4\hspace{\hfcolorboxsep}}}%
   {\fcolorbox[#1]{#2}{#3}{\hspace{\hfcolorboxsep}#4\hspace{\hfcolorboxsep}}}%
  \endgroup
}

\definecolor{light-gray}{gray}{0.75}
\setlength{\fboxsep}{2pt}

\begin{document}

\hfcolorbox{light-gray}{white}{%
  \includegraphics[width=2cm]{example-image}%
}

\end{document}

enter image description here

相关内容