6

Hi I want to use \fbox{} within a figure. Because the graphic has allot white parts I want to add a border to it for better view. But I recognised that \fbox{} adds a padding to the graphic which I don't like/want. I want the border on (or +1px) where the graphic "ends".

For illustrating purpose, this is my code:

\documentclass{report}
\usepackage{xcolor}
\newcommand\crule[3][black]{\textcolor{#1}{\rule{#2}{#3}}}
\begin{document}

  \crule[yellow]{2cm}{1cm} 

  \fbox{\crule[yellow]{2cm}{1cm}}

\end{document}

Gives me this:

Obviously in my proper code there is s.th. like this \fbox{\includegraphics[width=0.28\textwidth] {img/file.ext}} insted of the yellow box.

Any ideas how to remove the padding inside the frame?

  • 3
    The space on the right edge is simply the space in your \fbox command. But you want all of the surrounding space removed? – Alan Munn Jun 28 '17 at 15:15
  • 2
    Simply use \setlength{\fboxsep}{0pt}. – Bernard Jun 28 '17 at 15:18
  • @AlanMunn whoops. I removed the space. But yes all space (the ~3px space) like the answer shows below :) – user1234 Jun 28 '17 at 15:20
  • @AlanMunn thanks, adding % around the \fbox{ ... } lines fixed this issue for me. – Carsten Hagemann Jul 30 at 13:32
8

The border is determined by the \fboxsep length:

\documentclass{report}
\usepackage{xcolor}
\newcommand\crule[3][black]{\textcolor{#1}{\rule{#2}{#3}}}
\begin{document}

\crule[yellow]{2cm}{1cm}

\setlength{\fboxsep}{0pt}\fbox{\crule[yellow]{2cm}{1cm}}

\end{document}

enter image description here

  • 2
    for the OPs use case this will still make a box overfull by 2\fboxrule so may want to use \frame rather than \fbox, or put a \hspace*{-\fboxrule} either side – David Carlisle Jun 28 '17 at 15:46

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.