2

I want to center only one header and so far I have only found solutions that allow me to center ALL the section headers (e.g. \usepackage [centering] {titlesec})

I've come up with a work around that works without using any packages:

{\centering \paragraph {Paragraph1} \mbox {} \\ \par}

can this count any problems later on? So far it's working fine.

3
  • Is the heading a \paragraph, or a \section? The only way to assess whether this might be problematic is if we have a scope of your end goal.
    – Werner
    Commented Sep 21, 2018 at 22:37
  • the heading I want to center is a \paragraph. Commented Sep 22, 2018 at 10:14
  • right now, I'm just experimenting and trying to see what I can and can't use when I'm writing my first projects with latex (about 10-50 pages) depending Commented Sep 22, 2018 at 10:14

1 Answer 1

3

There's a reason for packages doing this - it provides consistency.

If the sectional unit doesn't specify any text justification, then you can go ahead and change it as you like. For example:

enter image description here

\documentclass{article}

\usepackage{lipsum}

\begin{document}

\section{A section}
\lipsum[1]

\clearpage % Just for this example

{\centering \section{Another section}}
\lipsum[1]

\end{document}

How would you know if the sectional unit has any justification specified? This depends on the type of packages you may be loading. For example, without loading any package, you can look at the standard document class to see what's going on. The above example uses article that defines

\newcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries}}

The only font-related changes that are specified is contained in the last visible argument and doesn't have anything related to justification (like \centering, \raggedleft or \raggedright). As such, using

{\centering <sectional unit> [optional \par]}

would suffice. The optional \par may depend on whether the section unit is a display (like \section, \subsection and \subsubsection) or run-in (like \paragraph and \subparagraph). For example, to centre a \paragraph I'd use

{\centering\paragraph{A paragraph}\mbox{}\par} Paragraph text \ldots

The \mbox{} actually sets the \paragraph title while \par causes the \centering to take effect for the group.

Similar things would hold for other sectional units under the standard document classes (like book and report), except for \chapter and \part.

More importantly though is to ask why you want a single format change while still using the same syntax. Is the element you want to be handled differently truly the same thing? Perhaps it'll be better to use

\begin{center}
  \normalfont\Large\bfseries % Similar formatting as \paragraph
  Paragraph-like title
\end{center}

You must log in to answer this question.

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