1

I am using a latex template that uses a pretty big side margin. In order to be able to display images properly, it offers the option to extend images into that margin, the according width is stored in the constant \widefigurewidth which is calculated as \def\widefigurewidth{\dimexpr(\marginparwidth + \textwidth + \marginparsep)}.

However, it still fits the caption of the image to the textwidth:

\begin{figure*}[h]
    \includegraphics[width=\widefigurewidth]{black.pdf}
    \caption{Lorem ipsum ...}
\end{figure*}
Lorem ipsum...

Results in: enter image description here

I tried explicitly setting the caption width:

\begin{figure*}[h]
    \centering
    \captionsetup{width=\widefigurewidth}
    \includegraphics[width=\widefigurewidth]{black.pdf}
    \caption{Lorem ipsum ...}
\end{figure*}
Lorem ipsum...

This is the result: enter image description here

Apparently, there is still some fixed margin to the right of the box that pushes it to the left. How can I override that?

Josef
  • 113
  • 1
    Welcome to TeX.SE! Can you please make your code snippet be compilable, then we do not have to guess what you are doing ... – Mensch Sep 30 '21 at 13:36
  • A simple solution is always: Put it in a box and some hspace and hfill behind the box. Some puristic people here won't like it. – MaestroGlanz Sep 30 '21 at 14:32
  • @Josef please have a look at the answer below if it meets the requirement – js bibra Oct 01 '21 at 00:55

1 Answers1

1

Using a minipage environment and testing the image and caption for textwidth then textwidth + marginparsep and finally for textwidth + marginparsep + marginparwidth

Thanks to @JohnKormylo -- https://tex.stackexchange.com/a/412713/197451

enter image description here

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{lipsum}

\begin{document} \texttt{figure=textwidth} \def\widefigurewidth{\dimexpr(\textwidth )}

\begin{figure}[h] \sbox0{\includegraphics[width=\widefigurewidth, height=2cm]{example-image}}% measure width \centering \begin{minipage}{\wd0} \usebox0 \caption{\lipsum[66]} \end{minipage} \end{figure}

\texttt{figure=textwidth + marginparsep}

\def\widefigurewidth{\dimexpr(\textwidth+\marginparsep)}

\begin{figure}[h] \sbox0{\includegraphics[width=\widefigurewidth, height=2cm]{example-image}}% measure width \centering \begin{minipage}{\wd0} \usebox0 \caption{\lipsum[66]} \end{minipage} \end{figure}

\texttt{figure=textwidth + marginparsep + marginparwidth} \def\widefigurewidth{\dimexpr(\textwidth+\marginparsep+\marginparwidth)}

\begin{figure}[h] \sbox0{\includegraphics[width=\widefigurewidth, height=2cm]{example-image}}% measure width \centering \begin{minipage}{\wd0} \usebox0 \caption{\lipsum[66]} \end{minipage} \end{figure} \end{document}

js bibra
  • 21,280