Рисунки не центрируются при переопределении титульного листа

Рисунки не центрируются при переопределении титульного листа

Я использую tufte-bookкласс. Если я переопределяю \maketitlepageкоманду, цифры перестают центрироваться. Вот MWE, воспроизводящий проблему:

\documentclass[justified, symmetric, titlepage]{tufte-book}
\usepackage{graphicx, lipsum}
\usepackage[english]{babel}

\makeatletter
\renewcommand{\maketitlepage}{
\thispagestyle{empty}
{\fontsize{15}{15}\scshape\@author\par}
\vspace{5cm}
{\fontsize{37}{37}\scshape\@title}
\newpage
\pagenumbering{arabic}}
\makeatother

\title{Title}
\author{Author}
\begin{document}
\maketitle

\lipsum[1-4]

\begin{figure}
\centering
\includegraphics[width=0.4\textwidth]{example-image-a}
\end{figure}

\lipsum[5]
\end{document}

И вот (нежелательный) результат.

введите описание изображения здесь

решение1

Я предлагаю вам написать отчет об ошибке на веб-странице Tufte.

Пожалуйста, посмотрите на следующий немного измененный код (здесь важно то, что я добавил опцию debugи добавил еще немного текста вокруг рисунка, чтобы можно было показать виновника с некоторыми дополнительными изменениями (раскомментировав остальной текст)):

\documentclass[%
  justified, 
  symmetric, 
  titlepage,
  debug       % <=======================================================
]{tufte-book}

\usepackage{graphicx, lipsum}
\usepackage[english]{babel}

\makeatletter
\renewcommand{\maketitlepage}{
\thispagestyle{empty}
{\fontsize{15}{15}\scshape\@author\par}
\vspace{5cm}
{\fontsize{37}{37}\scshape\@title}
\newpage
\pagenumbering{arabic}}
\makeatother

\title{Title}
\author{Author}


\begin{document}

\maketitle

\lipsum[1-4]

Now follows figure in code. % <=========================================
%Now follows figure in code. % <========================================
%Now follows figure in code. Now follows figure in code. 
%Now follows figure in code. Now follows figure in code. 
%Now follows figure in code. Now follows figure in code. 
%Now follows figure in code. Now follows figure in code. 
%Now follows figure in code. Now follows figure in code. 

\begin{figure}
\centering
\includegraphics[width=0.4\textwidth]{example-image-a} % [width=0.4\textwidth]
\caption{figure}
\label{fig:example}
\end{figure}

This is text after the figure in code. % <==============================
This is text after the figure in code. 
This is text after the figure in code. This is text after the figure in code. 
This is text after the figure in code. This is text after the figure in code. 
This is text after the figure in code. This is text after the figure in code. 
This is text after the figure in code. This is text after the figure in code. 

\lipsum[5]
\end{document}

Тогда вы получите тот же макет, что и у вас

макет

но в файле журнала вы можете найти следующее:

отладочная информация

Как видите, проблема в том, что oddвместо номера страницы evenраспознается неправильный номер.

Чтобы избавиться от этого, вы можете раскомментировать закомментированные строки, чтобы получить код:

\documentclass[%
  justified, 
  symmetric, 
  titlepage,
  debug       % <=======================================================
]{tufte-book}

\usepackage{graphicx, lipsum}
\usepackage[english]{babel}

\makeatletter
\renewcommand{\maketitlepage}{
\thispagestyle{empty}
{\fontsize{15}{15}\scshape\@author\par}
\vspace{5cm}
{\fontsize{37}{37}\scshape\@title}
\newpage
\pagenumbering{arabic}}
\makeatother

\title{Title}
\author{Author}


\begin{document}

\maketitle

\lipsum[1-4]

Now follows figure in code. % <=========================================
Now follows figure in code. % <========================================
Now follows figure in code. Now follows figure in code. 
Now follows figure in code. Now follows figure in code. 
Now follows figure in code. Now follows figure in code. 
Now follows figure in code. Now follows figure in code. 
Now follows figure in code. Now follows figure in code. 

\begin{figure}
\centering
\includegraphics[width=0.4\textwidth]{example-image-a} % [width=0.4\textwidth]
\caption{figure}
\label{fig:example}
\end{figure}

This is text after the figure in code. % <==============================
This is text after the figure in code. 
This is text after the figure in code. This is text after the figure in code. 
This is text after the figure in code. This is text after the figure in code. 
This is text after the figure in code. This is text after the figure in code. 
This is text after the figure in code. This is text after the figure in code. 

\lipsum[5]
\end{document}

Как вы можете видеть здесь

макет страницы

Рисунок центрирован, поскольку обходной путь перемещает текст вокруг рисунка на страницу 2. Это позволяет правильно распознавать используемую страницу, которую вы можете увидеть в отладочной информации:

введите описание изображения здесь

Так что перемещение кода для цифры вручную вниз или вверх может решить виновника, но это не автоматическая вещь. Чтобы вернуть автоматику, добавьте отчет об ошибке на веб-сайт tufte.

решение2

Помимо использования ручной маркировки с помощью \forcerectofloatи \forceversofloat, я успешно попробовал решение, описанное в документации пакета ifoddpage:

%\usepackage{ifoddpage}% works also without this package
...
\makeatletter
\renewcommand*{\@tufte@checkoddpage}{%
   \leavevmode \hbox \bgroup
   \checkoddpage
   \egroup
   \ifoddpage%
      \setboolean{@tufte@odd@page}{true}%
   \else%
      \setboolean{@tufte@odd@page}{false}%
   \fi%
}%
\makeatother

Я не проверял побочные эффекты и не тестировал другие примеры. Однако, это может быть хорошей точкой для начала.

Связанный контент