在一个双面ClassicThesis 文档中,我想将 2 个 TikZ 图片并排放置,以便它们的总宽度大于\textwidth
。
如果我使用 KOMA 的 addmargin 作为在这个问题中描述,子人物只是忽略它。回忆录\centerfloat
来自这个问题实际上并没有使图形居中。\makebox
从最后一个问题来看,子图似乎太复杂了,因为我需要在每个子图中创建一个框。
如何将 ClassicThesis 中的宽图相对于整个页面居中?也就是说,我希望左侧有 1 厘米的边距,右侧也有 1 厘米的边距。
更新:如果与不同的内外边距调整一起使用,以下答案对于获得绝对居中是有效的,例如begin{addmargin*}[-0.1\textwidth]{-0.3\textwidth}
\documentclass[
twoside,
openright
]{scrreprt}
\usepackage{filecontents}
\begin{filecontents}{pic.tikz}
\begin{tikzpicture}
\begin{axis}[
xmin=3.75, xmax=4.75,
]
\end{axis}
\end{tikzpicture}%
\end{filecontents}
\usepackage{subcaption, tikz, pgfplots}
\pgfplotsset{compat=1.6,
width=\textwidth,
height=0.25\textheight,
tick label style={font=\tiny},
legend style={font=\tiny, at={(0.0,1.05)}, anchor=south west},
legend columns=10,
xlabel shift={-1ex},
xlabel style={font=\tiny},
ylabel shift={-1em},
ylabel style={font=\tiny},
}%
\makeatletter
\newcommand*{\centerfloat}{%
\parindent \z@
\leftskip \z@ \@plus 0fil \@minus \textwidth
\rightskip\leftskip
\parfillskip \z@skip}
\makeatother
\begin{document}
Text width. Text width. Text width. Text width. Text width. Text width.
\begin{addmargin*}[-3em]{-4em}
Text for testing margins. Text for testing margins. Text for testing margins. Text for testing margins.
\begin{figure}[h]
\centerfloat
\begin{subfigure}[b]{0.65\textwidth}
\input{pic.tikz}%
\caption{Left picture}
\end{subfigure}
~
\begin{subfigure}[b]{0.65\textwidth}
\input{pic.tikz}%
\caption{Right picture}
\end{subfigure}
\end{figure}
\end{addmargin*}
\clearpage
Text for testing margins. Text for testing margins. Text for testing margins. Text for testing margins.
\begin{figure}[h]
\centerfloat
\begin{subfigure}[b]{0.65\textwidth}
\input{pic.tikz}%
\caption{Left picture}
\end{subfigure}
~
\begin{subfigure}[b]{0.65\textwidth}
\input{pic.tikz}%
\caption{Right picture}
\end{subfigure}
\end{figure}
\end{document}
答案1
请注意,pgfplots 选项width=\textwidth
意味着轴本身的\textwidth
宽度为 -45pt。剩余的 45pt 保留用于轴标签和刻度标签。这些标签的实际宽度不予考虑。在您的示例中,两张图片都小于.65\textwidth
。因此,您必须\raggedleft
对左图使用,\raggedright
对右图使用。
\begin{filecontents}{pic.tikz}
\begin{tikzpicture}
\begin{axis}[
xmin=3.75, xmax=4.75,
ymin=-1,ymax=5
]
\end{axis}
\end{tikzpicture}%
\end{filecontents}
\documentclass[
twoside,
openright
]{scrreprt}
\usepackage{showframe}% to show the page layout
\usepackage{lipsum}% only for dummy text
\usepackage{subcaption}
\usepackage{pgfplots}% loads also tikz, ...
\pgfplotsset{compat=1.6,% really 1.6? current version is 1.16
width=\linewidth,% <- changed
height=0.25\textheight,
tick label style={font=\tiny},
legend style={font=\tiny, at={(0.0,1.05)}, anchor=south west},
legend columns=10,
xlabel shift={-1ex},
xlabel style={font=\tiny},
ylabel shift={-1em},
ylabel style={font=\tiny},
}%
\makeatletter
\newcommand*{\centerfloat}{%
\parindent \z@
\leftskip \z@ \@plus 0fil \@minus \textwidth
\rightskip\leftskip
\parfillskip \z@skip}
\makeatother
\begin{document}
\lipsum[1]
\begin{figure}[hb]
\centerfloat
\begin{subfigure}[b]{0.65\textwidth}
\raggedleft% <- added
\input{pic.tikz}%
\caption{Left picture}
\end{subfigure}%
~
\begin{subfigure}[b]{0.65\textwidth}
\raggedright% <- added
\input{pic.tikz}%
\caption{Right picture}
\end{subfigure}
\end{figure}
\lipsum[2]
\end{document}
结果:
如果要使用addmargin*
,则必须在figure
环境内使用此环境:
\begin{filecontents}{pic.tikz}
\begin{tikzpicture}
\begin{axis}[
xmin=3.75, xmax=4.75,
ymin=-1,ymax=5
]
\end{axis}
\end{tikzpicture}%
\end{filecontents}
\documentclass[
twoside,
openright
]{scrreprt}
\usepackage{showframe}% to show the page layout
\usepackage{lipsum}% only for dummy text
\usepackage{subcaption}
\usepackage{pgfplots}% loads also tikz, ...
\pgfplotsset{compat=1.6,% really 1.6? current version is 1.16
width=\linewidth,% <- changed
height=0.25\textheight,
tick label style={font=\tiny},
legend style={font=\tiny, at={(0.0,1.05)}, anchor=south west},
legend columns=10,
xlabel shift={-1ex},
xlabel style={font=\tiny},
ylabel shift={-1em},
ylabel style={font=\tiny},
}%
\begin{document}
\lipsum[1]
\begin{figure}[hb]
\begin{addmargin}{-.2\textwidth}
\centering
\begin{subfigure}[b]{0.65\textwidth}
\raggedleft% <- added
\input{pic.tikz}%
\caption{Left picture}
\end{subfigure}%
~
\begin{subfigure}[b]{0.65\textwidth}
\raggedright% <- added
\input{pic.tikz}%
\caption{Right picture}
\end{subfigure}
\end{addmargin}
\end{figure}
\lipsum[2]
\end{document}
结果: