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?

4
  • How do you use this exactly? Does it start a new paragraph, i.e. is there a empty line before it? Apr 18 '11 at 15:27
  • @Martin Scharrer The picture has exactly the size of a whole page. So there is no paragraph. Apr 18 '11 at 15:28
  • 1
    The size doesn't matter. There might be a paragraph nonetheless. Apr 18 '11 at 15:32
  • @Martin Scharrer Yes that's true, I tried \centering for each graphic and this would work, but I think the better solution would be the code in your answer. Thanks. Apr 18 '11 at 15:34
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}}
2
  • This seems like a good idea, but unfortunately I get an exception ! Illegal unit of measure (pt inserted). <to be read again> * l.136 ...p-2*\fboxrule\relax]{questionnaire1.png}} ? ´ Apr 18 '11 at 15:30
  • @Roflcoptr: I fixed it. The * caused the troubles. They are not required anyway. Apr 18 '11 at 15:34
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} 
1
  • 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. Apr 18 '11 at 15:36

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.