居中图形周围有双边框

居中图形周围有双边框

我需要将图像置于页面中央并用双边框装饰。到目前为止,我有两个嵌套的fboxes

{
    \setlength{\fboxsep}{5px}
    \setlength{\fboxrule}{3px}
    \noindent\makebox[\linewidth]{
        \fbox{
            {
                \setlength{\fboxsep}{3px}
                \setlength{\fboxrule}{1px}
                \fbox{
                    \includegraphics[scale=1.0]{test.png}
                }
            }
        }
    }
}

这给了我两个边框,但填充却乱七八糟:

在此处输入图片描述

我该如何修复填充问题?或者有更好的方法来实现我想要的效果吗?

答案1

这个最小的工作示例可以实现您想要的功能:

\documentclass[]{article}

\usepackage{graphics}

\begin{document}
\begin{center}
  \fboxsep=5pt\relax\fboxrule=3pt\relax
  \fbox{%
    \fboxsep=3pt\relax\fboxrule=1pt\relax
    \fbox{\includegraphics{example-image}}}
\end{center}
\end{document}

在此处输入图片描述

答案2

您有多个未受保护的行尾,它们算作空格:

{%
    \setlength{\fboxsep}{5px}%
    \setlength{\fboxrule}{3px}%
    \noindent\makebox[\linewidth]{%
        \fbox{%
            {%
                \setlength{\fboxsep}{3px}%
                \setlength{\fboxrule}{1px}%
                \fbox{%
                    \includegraphics[scale=1.0]{test.png}%
                }%
            }%
        }%
    }%
}

这里有一个实现,允许分别指定规则厚度和间隔。内部\ExplSyntaxOn空格和行尾将被忽略。

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\doublefbox}{ O{} m }
 {
  \group_begin:
  \keys_set:nn { kontextify/doublefbox } { #1 }
  \kontextify_doublefbox:n { #2 }
  \group_end:
 }

\keys_define:nn { kontextify/doublefbox }
 {
  rule1 .dim_set:N = \l__kontextify_ruleone_dim,
  rule2 .dim_set:N = \l__kontextify_ruletwo_dim,
  sep1  .dim_set:N = \l__kontextify_sepone_dim,
  sep2  .dim_set:N = \l__kontextify_septwo_dim,
  rule1 .initial:n = \fboxrule,
  rule2 .initial:n = \fboxrule,
  sep1  .initial:n = \fboxsep,
  sep2  .initial:n = \fboxsep,
 }

\cs_new_protected:Nn \kontextify_doublefbox:n
 {
  \dim_set:Nn \fboxrule { \l__kontextify_ruleone_dim }
  \dim_set:Nn \fboxsep  { \l__kontextify_sepone_dim }
  \fbox
   {
    \dim_set:Nn \fboxrule { \l__kontextify_ruletwo_dim }
    \dim_set:Nn \fboxsep  { \l__kontextify_septwo_dim }
    \fbox
     {
      #1
     }
   }
 }
\ExplSyntaxOff

\begin{document}

\doublefbox{\rule{1cm}{1cm}}

\bigskip

\doublefbox[rule1=1pt,sep1=3pt]{\rule{1cm}{1cm}}

\bigskip

\doublefbox[rule1=1pt,sep1=3pt,rule2=3pt,sep2=5pt]{\rule{1cm}{1cm}}

\end{document}

在此处输入图片描述

相关内容