4

I am using the ClassicThesis template. Infrequently, I want to include figures wider than the \textwidth or \linewidth. My current workaround is:

\begin{figure}
\centering
\hspace*{-2cm} 
\captionsetup{margin={-0pt,-2cm}}
\makebox[\textwidth][c]{\includegraphics[width=1.3\textwidth]{images/MyImage.pdf}}
 \caption{Here goes my caption}
  \label{fig:MyImage} 
\end{figure}

The problem is: I have to adjust the -2cm to +2cm depending if the pdf output is a 'left' or a 'right' side. This is because ClassicThesis uses a substantially larger outside margin. So, I would have to go through my entire document (once it is completed) and then eyeball whether it is a 'left' page or not and then adjust the -2cm or +2cm accordingly.

Is there a more elegant way of doing this?

And another question building on that, would this more elegant solution also work for my longtables? Currently, I use this:

{\small 
\setlength\LTleft{-40pt}
\setlength\LTright{-40pt}
\setlength\LTcapwidth{\linewidth}
\begin{longtable}{p{1.5cm}p{14 cm}}
\caption{My Caption} \\
\toprule
Column A & Column B  \\
\hline
\endfirsthead
\multicolumn{2}{@{}l}{\ldots continued}\\\hline
Column A & Column B \\\hline
\endhead % all the lines above this will be repeated on every page
\hline
\multicolumn{2}{r@{}}{continued \ldots}\\
\endfoot
\hline
\endlastfoot

Entry Column A & Entry Column B \

\end{longtable}% \label{tab:MyTab}% }

luki
  • 1,796
jbri
  • 41

3 Answers3

2

This creates a new environment, widefigure. It doesn't actually center the figure on the page, but figures on even and odd pages will line up.

You need to run it twice, since iffoddpage uses the aux file.

It appears one cannot change \LTleft or \LTright in the middle of a longtable.

\documentclass{book}
\usepackage{ClassicThesis}

\usepackage{ifoddpage}% \value{page} is not reliable

\newlength{\LRshift} \setlength{\LRshift}{\dimexpr 0.5\oddsidemargin-0.5\evensidemargin}

\newsavebox{\widefigurebox} \newenvironment{widefigure}[1][tbp]{\figure[#1] \begin{lrbox}{\widefigurebox}}% {\end{lrbox}% \checkoddpage \ifoddpage \LRshift=-\LRshift \fi% local change \leavevmode\rlap{\hspace{\dimexpr \LRshift + 0.5\textwidth - 0.5\wd\widefigurebox} \usebox\widefigurebox}% \endfigure}

\usepackage{graphicx} \usepackage{caption} \usepackage{lipsum}

\begin{document} \begin{widefigure} \begin{minipage}{1.3\textwidth} \includegraphics[width=\linewidth]{example-image} \caption{Here goes my caption} \label{fig:MyImage} \end{minipage}% \end{widefigure}

\lipsum[1-4]

\begin{widefigure} \begin{minipage}{1.3\textwidth} \includegraphics[width=\linewidth]{example-image} \caption{Here goes my caption} \label{fig:MyImage} \end{minipage}% \end{widefigure}

\end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
1

With use of the changepage package:

\documentclass{article}
\usepackage{graphicx}
\usepackage{booktabs, longtable}           
\usepackage[strict]{changepage} % <---

%---------------- show page layout. don't use in a real document! \usepackage{showframe} \renewcommand\ShowFrameLinethickness{0.15pt} \renewcommand*\ShowFrameColor{\color{red}} %---------------------------------------------------------------% \usepackage{lipsum}

\begin{document} \section{Introduction} \lipsum[1][1-4] \begin{figure}[ht] \begin{adjustwidth}{}{\dimexpr-\marginparwidth-\marginparsep} \includegraphics[width=\linewidth]{example-image-duck} \caption{Image wich width is equal to \texttt{text width + marginparwidth + marginparsep}} \end{adjustwidth} \end{figure}

\lipsum[1][5-8]

\begin{adjustwidth}{}{\dimexpr-\marginparwidth-\marginparsep} \begin{longtable}{*{2}{p{\dimexpr0.5\linewidth-2\tabcolsep}}} \caption{Long table wider than text width}\ \toprule \lipsum[66] & \lipsum[66] \ \midrule \lipsum[66] & \lipsum[66] \ \bottomrule \end{longtable} \end{adjustwidth}

\lipsum[2] \end{document}

enter image description here

Addedndum: Above proposed solution doesn't work well in two side document. In such cases a possible work around can be manualy split long table into two (and more, if necessary) parts, and each enclose in table float as is done in MWE below:

\documentclass[twoside]{article}
\usepackage{graphicx}
\usepackage{booktabs, longtable}
\usepackage[strict]{changepage} % <---
\usepackage[skip=1ex]{caption}

%---------------- Show page layout. Don't use in a real document! \usepackage{showframe} \renewcommand\ShowFrameLinethickness{0.15pt} \renewcommand*\ShowFrameColor{\color{red}} %---------------------------------------------------------------% \usepackage{lipsum}% For dummy text. Don't use in a real document

\begin{document} \section{Introduction} \lipsum[1][1-2] \begin{figure}[ht] \begin{adjustwidth}{}{\dimexpr-\marginparwidth-\marginparsep} \includegraphics[width=\linewidth, height=0.5\linewidth]{example-image-duck} \caption{Wide image} \end{adjustwidth} \end{figure} \lipsum[1][3-5]

\begin{table}[b]    % &lt;--- observe [b]

\begin{adjustwidth}{}{\dimexpr-\marginparwidth-\marginparsep} % <--- observe \caption{Long table wider than text width} \label{tab:long} \begin{tabular}{{2}{p{\dimexpr0.5\linewidth-2\tabcolsep}}} \toprule \lipsum[66] & \lipsum[66] \ \midrule \multicolumn{2}{r}{\footnotesize\textit{Continue on the next page}} \end{tabular} \end{adjustwidth} \end{table} % \begin{table}[t] % <--- observe [t] \begin{adjustwidth}{}{\dimexpr-\marginparwidth-\marginparsep} % <--- observe \ContinuedFloat \caption[]{Long table wider than text width -- continued from previous page} \begin{tabular}{{2}{p{\dimexpr0.5\linewidth-2\tabcolsep}}} \toprule \lipsum[66] & \lipsum[66] \ \bottomrule \end{tabular} \end{adjustwidth} \end{table}

\lipsum[2] \end{document}

enter image description here

Zarko
  • 296,517
  • Needs some work for a twoside document class. – John Kormylo Apr 07 '21 at 13:05
  • @JohnKormylo, OP didn't mentioned, that has two side document, so I didnt give any attention to this case. – Zarko Apr 07 '21 at 14:19
  • @JohnKormylo, using adjuastbox* interchange left and right margins according on which page -- odd or even page -- is, however this doesn't work middle of long table. One (simple) way to overcome this, is split long table to smaller parts or make extension from text width symmetrical (what as I understood OP, is not desired). – Zarko Apr 07 '21 at 14:48
  • Thanks for all your help! I think the workaround for the Figures is perfect. The Longtable still doesn't work. In my example, even pages are fine, odd aren't. If I get that right, a symmetrical text width extension implies that odd and even pages are treated the same. If that's the case, then I can't maximise the space used on a page and it is not desired. If I got that wrong or is a sweet workaround, please let me know! In addition: What is a smart way to split a longtable? I do not want to have several tables listed in my Table of Tables. Thanks! – jbri Apr 15 '21 at 08:25
  • @jbri, I haven't ClassicThesis template not use it. I suspect, that it define two side document . As I noted in above comment, in this case adjustwidth doesn't work with long table. Also I describe a possible work around in such a cases. I will add an example to answer ASAP. – Zarko Apr 15 '21 at 08:36
  • @Zarko Thank you very much. I ran into a problem with your solution for the figure and a rather long caption. I ended up combining it with this solution link. It took me a while to find out that the label has to go right after the caption. Now it works like a charm! – jbri Apr 18 '21 at 00:16
  • @jbri, I wonder now, that is your problem. In giving link is not solutions for images and table wider that text width. Please, clarify your question. – Zarko Apr 18 '21 at 00:27
0

Sorry for being unspecific by answering as a comment, I ran out of characters to use. Now, as a full answer:

My challenge was that a long caption was still cut off according to the old \textwidth

I linked the other solution which inspired this workaround:

\documentclass[twoside]{article}
\usepackage{graphicx}
\usepackage{booktabs, longtable}
\usepackage[strict]{changepage} 
\usepackage[skip=1ex]{caption}

%---------------- Show page layout. Don't use in a real document! \usepackage{showframe} \renewcommand\ShowFrameLinethickness{0.15pt} \renewcommand*\ShowFrameColor{\color{red}} %---------------------------------------------------------------% \usepackage{lipsum}% For dummy text. Don't use in a real document

\begin{figure}[ht] \begin{adjustwidth}{}{\dimexpr-\marginparwidth-\marginparsep} \sbox0{\includegraphics[width=\linewidth]{images/example-image-duck}} \begin{minipage}{\wd0} \usebox0 \caption{Here goes my very long caption that would usually be cut off right after reaching the width of \textwidth, but now it can be even longer and is neatly aligned with the overall text} \label{fig:IHaveToMakeSureToPutTheLabelRightInHereOtherwiseReferenesWontWork} \end{minipage} \end{adjustwidth} \end{figure}

  • I still have a problem with tables and using the solution by @Zarko The rules (toprule, midrule and specialrule) all run to the very end of the page without stopping where they are supposed to do that. I fiddled with cropping the specialrule \specialrule{3pt}{2pt}{2pt}(l{3em}r{12em}) where the 3em and 12em should do the job, but they don't. Thanks for any help! – Jbri Apr 18 '21 at 00:54