2

I included a graphic the following way:

\includegraphics[width=1\textwidth]{questionnaire1.png}

Then I changed it so that a frame is drawn around the graphic:

\fbox{\includegraphics[width=1\textwidth]{questionnaire1.png}}

But now, the whole graphic with the border is move 1-2 cm to the right side of the page so that is not in line with the other content. How can I change this?

lockstep
  • 250,273

2 Answers2

6

Depends on why it is moving. Probably you forgot \fboxsep, \fboxrule and/or \parindent.

\documentclass{article}
\usepackage{lipsum,xcolor}
\begin{document}
\lipsum[1]

\fbox{%
 \color{red}\rule{\textwidth}{1cm}}

\noindent\fbox{%
 \color{red}\rule{\textwidth}{1cm}}

\noindent\fbox{%
 \color{red}\rule{\dimexpr\textwidth-2\fboxrule-2\fboxsep}{1cm}}

\noindent\makebox[\textwidth]{%
 \fbox{%
  \color{red}\rule{\dimexpr\textwidth}{1cm}}}

\noindent
 \begingroup\fboxsep=0pt
 \fbox{%
  \color{red}\rule{\dimexpr\textwidth-2\fboxrule}{1cm}}
 \endgroup
\end{document} 
Ulrike Fischer
  • 327,261
  • 1
    Yes, \noindent\makebox[\textwidth] is probably the best thing to do. With [c] as second optional argument you can center the image even when it is wider than \textwidth when the frame is added. – Martin Scharrer Apr 18 '11 at 15:36
4

I would add \noindent to avoid paragraph indention, which might be the case here. Also the \fbox adds some space around its content, i.e. \fboxsep on each side. I would subtract this amount from the image width to have the image including the frame exactly \textwidth wide. You could also subtract the line width of the frame as well.

\noindent\fbox{\includegraphics[width=\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax]{questionnaire1.png}}
Martin Scharrer
  • 262,582