1

I need to center an image on the page and decorate it with a double border. What I have so far is two nested fboxes:

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

This gives me two borders, but with messed up padding:

enter image description here

How can I fix the padding issue? Or is there a better way to achieve what I want?

  • this is not MWE, please post MWE @kontexify – Biki Teron Nov 22 '17 at 18:26
  • 1
    The additional horizontal spaces are caused by line ends that become spaces. End the lines with the comment char %. – Heiko Oberdiek Nov 22 '17 at 18:34
1

This minimal working example does what you want:

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

enter image description here

1

You have several unprotected end-of-lines, that count as spaces:

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

Here's an implementation that allows to specify separately the rule thickness and the separation. Inside \ExplSyntaxOn spaces and end-of-lines are ignored.

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

enter image description here

  • Thanks for the examples, and the tip about end-of-lines. I do find @Skillmon's solution to be much neater though. – kontextify Nov 23 '17 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.