在包含 A3 和 A4 纸张尺寸的文档中居中标题

在包含 A3 和 A4 纸张尺寸的文档中居中标题

为了将多幅图放在一行上,我的文档有 A4(纵向)和 A3(横向)页面。为了设置 A3 页面,我创建了一个新环境(我从另一个解决方案中改编的技巧)。请注意,我无法为 A3 页面创建单独的 PDF 并将其添加进去,因为图引用、页面、部分等会不断变化。

但是,当我在 A3 页面上绘制图形时,主标题的位置就像 A4 一样。(见下文)如何将标题相对于 A3 页面居中?

A3 文档标题未居中

我在 A4 部分中包含了不带文本的代码:

\documentclass[12pt]{article}

% Pictures & Labels
\usepackage[capitalise]{cleveref}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{textcomp}
\usepackage{float}
\usepackage[section]{placeins}
% Paper Style
\usepackage[a4paper,
            width=150 mm,
            top=25 mm,
            bottom=25 mm]
            {geometry}
\usepackage[title,toc,page]{appendix}
%% Allow A3 sheets - - New environment
\newenvironment{a3page}
{\newpage
\advance\textwidth\pdfpagewidth
\headwidth = \textwidth 
\pdfpagewidth=2\pdfpagewidth}
{\newpage}

\begin{document}

%% Start A3 page
\begin{a3page}
\section{Title}
\begin{figure}[H]
\centering
        \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=4cm]{images/pic.png}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=4cm]{images/pic.png}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=4cm]{images/pic.png}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
                \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=4cm]{images/pic.png}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=4cm]{images/pic.png}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=4cm]{images/pic.png}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.05\textwidth}
                \centering
                \includegraphics[height=4cm]{images/pic2.png}
        \end{subfigure}%
        \centering
        \caption{This caption isn't centered}\label{fig:}
\end{figure}
%
%
\end{a3page}
\end{document}

答案1

页面布局还有很多东西,不仅仅是众所周知的参数,例如\textwidth。例如,TeX 内部使用\hsize来构建段落。最好的方法是,将其留给geometry

不幸的是,\newgeometry不允许在纵向和横向之间切换或在文档中更改纸张大小。但可以编写一个宏,允许这样做。它基本上是 的更改副本\newgeometry\newgeometryfull在此处调用。请小心使用它!此外,必须设置\pdfpageheight\pdfpagewidth,以便 PDF 查看器也知道纸张大小。这是在a3page环境中完成的。

我删除了该行\headwidth=\textwidth,因为\headwidth在您的示例中不存在。但您可能需要它来处理此处不存在的标题。

结果:

在此处输入图片描述

代码:

\documentclass[12pt]{article}

% Pictures & Labels
\usepackage[capitalise]{cleveref}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{textcomp}
\usepackage{float}
\usepackage[section]{placeins}
% Paper Style
\usepackage[a4paper,
            width=150 mm,
            top=25 mm,
            bottom=25 mm]
            {geometry}
\usepackage[title,toc,page]{appendix}

\usepackage{lipsum}

\makeatletter
% like \newgeometry, but also allows change of landscape/portrait and paper size
% to be used with caution!
\newcommand{\newgeometryfull}[1]{%
  \clearpage
  \Gm@restore@org
  \Gm@initnewgm
%  \Gm@newgmtrue
  \setkeys{Gm}{#1}%
%  \Gm@newgmfalse
  \Gm@process
  \ifnum\mag=\@m\else\Gm@magtooffset\fi
  \Gm@changelayout
  \Gm@showparams{newgeometry}}%
\makeatother

%% Allow A3 sheets - - New environment
\newenvironment{a3page}{%
    \newgeometryfull{a3paper,landscape,width=360 mm,top=25 mm,bottom=25 mm}
    % set the correct dimension for the PDF viewer
    \pdfpageheight=\paperheight
    \pdfpagewidth=\paperwidth
}{%
    \restoregeometry
    % set the correct dimension for the PDF viewer
    \pdfpageheight=\paperheight
    \pdfpagewidth=\paperwidth
}

\begin{document}
\section{A test}
\lipsum[1]

%% Start A3 page
\begin{a3page}
\section{Title}
\lipsum[1]

\begin{figure}[H]
\centering
        \begin{subfigure}[t]{0.14\textwidth}
                \centering
                \includegraphics[height=4cm]{example-image-9x16.png}
                \caption{}
                \label{subfig:a}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.14\textwidth}
                \centering
                \includegraphics[height=4cm]{example-image-9x16.png}
                \caption{}
                \label{subfig:b}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.14\textwidth}
                \centering
                \includegraphics[height=4cm]{example-image-9x16.png}
                \caption{}
                \label{subfig:c}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.14\textwidth}
                \centering
                \includegraphics[height=4cm]{example-image-9x16.png}
                \caption{}
                \label{subfig:d}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.14\textwidth}
                \centering
                \includegraphics[height=4cm]{example-image-9x16.png}
                \caption{}
                \label{subfig:e}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.14\textwidth}
                \centering
                \includegraphics[height=4cm]{example-image-9x16.png}
                \caption{}
                \label{subfig:f}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.14\textwidth}
                \centering
                \includegraphics[height=4cm]{example-image-9x16.png}
                \caption{}
                \label{subfig:g}
        \end{subfigure}%
        %
        \caption{This caption isn't centered}\label{fig:}
\end{figure}

\lipsum[1]
\end{a3page}

\section{Another test}
\lipsum[1]

\end{document}

答案2

这是我不太优雅的解决方案。我用

\eject \pdfpagewidth=16.5in \pdfpageheight=11.7in

使页面具有不同的大小。此解决方案基于此回答。现在标题已居中。

A4之后是A3纸

\documentclass[12pt]{article}

% Pictures & Labels
\usepackage[capitalise]{cleveref}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{textcomp}
\usepackage{float}
\usepackage[section]{placeins}
% Paper Style
\usepackage[a4paper,
            width=150 mm,
            top=25 mm,
            bottom=25 mm]
            {geometry}
\usepackage[title,toc,page]{appendix}
 \begin{document}
A4 paper

%% Start A3 page
\eject \pdfpagewidth=16.5in \pdfpageheight=11.7in
\section{Title}
\begin{figure}[H]
\centering
        \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=1cm]{example-image-b}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=1cm]{example-image-b}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=1cm]{example-image-b}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
                \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=1cm]{example-image-b}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=1cm]{example-image-b}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.16\textwidth}
                \centering
                \includegraphics[height=1cm]{example-image-b}
                \caption{}
                \label{subfig:}
        \end{subfigure}%
        %
        %
        \begin{subfigure}[t]{0.05\textwidth}
                \centering
                \includegraphics[height=1cm]{example-image-b}
        \end{subfigure}%
        \centering
        \caption{This caption isn't centered}\label{fig:}
\end{figure}

\end{document}

相关内容