[Tex/LaTex] Centering Headings – list of contents – but not chapters

formattingtable of contents

I need to center some sections using normal size fonts in the front sections of a document, but not the chapter headings. So, I need a "Contents" and "List of Tables" and "List of Figures" centered and all uppercase before the list of the appropriate entries. Then, when I have chapter headings (1, and 1.1) those headings need to be on the left of the page (not centered, mixed case, also in normal size fonts). References at the end, also needs to be centered like "Contents." The table of contents list all need to be in plain fonts (as shown). So, basically, I need to have "Contents," "List of Figures," etc., and "References" centered, without disturbing anything else. One other note, the "Contents," etc. are supposed to be all uppercase… The chapter titles are supposed to be mixed case. Any help is appreciated.

%% LyX 2.0.7 created this file.  For more info, see http://www.lyx.org/.   
%% Do not edit unless you really know what you are doing. 
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\makeatletter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands. 
\usepackage{titlesec}
\titleformat*{\section}{\bfseries\normalsize}
\titleformat*{\subsection}{\bfseries\normalsize}
\titleformat*{\subsubsection}{\bfseries\normalsize}

\usepackage{titletoc}

\titlecontents{section} % set formatting for \section - \subsection must be formatted separately   
[2.3em]                 % adjust left margin 
{\rmfamily}             % font formatting
{\contentslabel{2.3em}} % section label and offset
{\hspace*{-2.3em}}
{\titlerule*[1pc]{.}\contentspage}

\makeatother

\usepackage{babel} 

\begin{document}
This is a test...
\tableofcontents
\listoffigures

and this is after the table of contents

\section{This is a section}

test one two three as seen on TV

\subsection{this is sub}

test sub...

\section{this is the second section}

\addcontentsline{toc}{section}{\protect\underline{\refname}}
\bibliographystyle{plain}
\bibliography{C:/Users/csibona/Documents/SocialNetwork}

\appendix

\addcontentsline{toc}{section}{\protect\underline{Appendix}}
\pagebreak
\section{Ah, an appendix}

\end{document}

Best Answer

Here's one possibility, using the titlesec package. The idea is to define two commands allowing you to switch the section title formatting as many times as required; \CentSections gives you centered uppercased headings and \StdSections gives you the standard flushed, sentence-case headings.

\documentclass[english]{article}
\usepackage{babel} 
\usepackage{titlesec}
\usepackage{titletoc}

\titleformat*{\section}{\bfseries\normalsize}
\titleformat*{\subsection}{\bfseries\normalsize}
\titleformat*{\subsubsection}{\bfseries\normalsize}

\titlecontents{section} % set formatting for \section - \subsection must be formatted separately   
  [2.3em]                 % adjust left margin 
  {\rmfamily}             % font formatting
  {\contentslabel{2.3em}} % section label and offset
  {\hspace*{-2.3em}}
  {\titlerule*[1pc]{.}\contentspage}

\newcommand\CentSections{
  \titleformat{\section}
  {\normalfont\bfseries\normalsize\centering}{\thesection}{1em}{\MakeUppercase}
}
\newcommand\StdSections{
  \titleformat{\section}
  {\normalfont\bfseries\normalsize}{\thesection}{1em}{}
}

\begin{document}

\CentSections
\tableofcontents
\listoffigures
\listoftables

\StdSections
\section{This is a standard section}
\subsection{This is a subsection}
\section{This is the second standard section}
\subsection{This is another subsection}

\CentSections
\addcontentsline{toc}{section}{\protect\underline{\refname}}
\bibliographystyle{plain}
\bibliography{biblio}

\StdSections
\appendix
\section{An appendix}

\end{document}

An image of the resulting document:

enter image description here

Related Question