2

I am centering a text:

\documentclass{memoir}

\renewcommand{\partpageend}{} %% can write after part title
\usepackage{graphicx}



\renewcommand{\beforepartskip}{% added <<<<<<<<<<<<<<<<<
        \centering
        \includegraphics[width=0.4\linewidth]{example-image} 
        \par\vfill
}

\begin{document}
    
    \part{This is a title}
    
    \begin{center}
        \textbf{This text is being centered and that's what I want.}
        \vfill
    \end{center}
    
    \newpage
    
This text should not be centered anymore.
This text should not be centered anymore.
This text should not be centered anymore.
This text should not be centered anymore.
This text should not be centered anymore.
This text should not be centered anymore.
This text should not be centered anymore.
This text should not be centered anymore.

\end{document}

But after \end{center} everything else is still being centered.

Thank you in advance.

3
  • 3
    Please provide a full but minimal example that shows this problem such that others can copy and test the code as is on their system to confirm or deny the issue.
    – daleif
    Commented May 30, 2022 at 16:22
  • I have edited the opening posting. Commented May 30, 2022 at 16:40
  • 7
    This is probably caused by the \centering in your \beforepartskip. Surround that with another pair of braces: {\centering ... \par\vfill} Commented May 30, 2022 at 16:46

1 Answer 1

4

As has already been noted by @HeikoTheißen in a comment, the centering issue you're experiencing arises because the \centering command in the definition of \beforepartskip is not in a (TeX) group and hence persists. The fact that the document also features, separately, a center environment, is immaterial.

One way to fix this is to replace

\renewcommand{\beforepartskip}{% added <<<<<<<<<<<<<<<<<
        \centering
        \includegraphics[width=0.4\linewidth]{example-image} 
        \par}\vfill
}

with

\renewcommand{\beforepartskip}{{% added <<<<<<<<<<<<<<<<<
        \centering
        \includegraphics[width=0.4\linewidth]{example-image}
        \par}\vfill
}

Can you spot the extra instances of { and }?

4
  • 1
    Should the \par be inside the group or not?
    – daleif
    Commented May 30, 2022 at 16:59
  • 1
    @daleif - I've updated my answer to reflect your and egreg's points.
    – Mico
    Commented May 30, 2022 at 17:01
  • Thank you very much. Will \centering be obsolete soon? Commented May 30, 2022 at 17:04
  • 1
    @Brayanokles - You asked, "Will \centering be obsolete soon?" Absolutely not. The LaTeX environment called center is actually defined around the command called \centering.
    – Mico
    Commented May 30, 2022 at 17:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .