[Tex/LaTex] \fbox command destroys margin

boxesframedmarginsspacing

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?

Best Answer

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