我正在使用经典论文 模板。偶尔,我想包含比\textwidth
或更宽的图形\linewidth
。我目前的解决方法是:
\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}
问题是:我必须根据 pdf 输出是“左”还是“右”来调整-2cm
。+2cm
这是因为 ClassicThesis 使用了更大的外部边距。因此,我必须浏览整个文档(一旦完成),然后目测它是否是“左”页,然后相应地调整-2cm
或+2cm
。
有没有更优雅的方法来做到这一点?
另一个问题是,这种更优雅的解决方案是否也适用于我的长桌?目前,我使用这个:
{\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}%
}
答案1
这将创建一个新的环境,widefigure。它实际上不会将图形置于页面的中心,但偶数页和奇数页上的图形将对齐。
您需要运行它两次,因为 iffoddpage 使用 aux 文件。
看来人们无法改变\LTleft
或\LTright
处于长桌的中间。
\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}
答案2
使用该changepage
包:
\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}
附註:
上述建议的解决方案在双面文档中效果不佳。在这种情况下,一种可能的解决方法是手动将长表拆分为两个(如果需要,可以拆分为更多)部分,并将每个部分括在table
浮动中,如下面的 MWE 中所做的那样:
\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] % <--- 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}
答案3
抱歉,以评论的形式回答不够具体,我已经用完了所有字符。现在,作为完整答案:
我的挑战是,根据旧的 \textwidth,长标题仍然被截断
我链接了启发此解决方法的其他解决方案:
\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}