0

This question is about how to center all the sections (including chapters) without centering subsections.

I have browsed all the related questions asked here but I found no one to which my question is duplicate. I have tried a proposed solution that centers all the headlines. But I do not know how to partially center the headlines.

Need your help, thanks so much, with my codes:

\documentclass[a4paper]{article}
\usepackage{mathtools}
\usepackage{colonequals}
\usepackage{mathrsfs}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsmath}`enter code here`
\usepackage{natbib}
\usepackage{bm}
\usepackage{mathdots}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{rotating, threeparttable, booktabs}
\usepackage{color}
\usepackage{dcolumn}
\usepackage{type1cm}
%\usepackage[margin=1.2in]{geometry}
%\usepackage{times}
\captionsetup{font=sf,font=small}
\setlength{\bibsep}{2pt}
\captionsetup{font=sf,font=small,labelfont=bf,textfont=bf}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{pro}[thm]{Proposition}
\newtheorem{assump}{Assumption}
\newtheorem{axiom}{Axiom}
\newtheorem{conj}{Conjecture}
\theoremstyle{definition}
\newtheorem{defi}[thm]{Definition}
\newtheorem{exam}[thm]{Example}
\newtheorem{exer}{Exercise}
\newtheorem*{rem}{Remark}
\newtheorem*{notation}{Notation}
%\renewcommand{\proofname}{\textbf{\textup{Proof}}}
\renewcommand*{\qedsymbol}{$\blacksquare$}
%\renewcommand{\baselinestretch}{2}
\renewcommand{\textfraction}{0.15}
\renewcommand{\topfraction}{0.85}
\renewcommand{\bottomfraction}{0.65}
\renewcommand{\floatpagefraction}{0.60}
%\renewcommand\familydefault{\sfdefault}


\newcommand\laref{\fontsize{12}{20pt}\selectfont \smallskip\noindent%
\hangindent=19pt}
\newcommand\xitem{\par\noindent\hangindent=8mm}



% To increase line space in footnote.
%
\let\oldfootnote\footnote
\renewcommand\footnote[1]{\oldfootnote{%
  \renewcommand\baselinestretch{1.5}%
  \large\scriptsize\ignorespaces#1}}
\addtolength{\footnotesep}{1pt}


%centering all titles
\usepackage{sectsty}
\sectionfont{\centering}
6
  • 1
    If your .tex file contains a line \documentclass, you are not writing a 'plain TeX' document, but a LaTeX document. The correct answer to your problem depends on you specifying whether you are using LaTeX or not.
    – jon
    Sep 26, 2014 at 3:09
  • @jon, much appreciated, I see. :)
    – Yes
    Sep 26, 2014 at 3:11
  • 1
    And the article class doesn't define chapters!
    – user11232
    Sep 26, 2014 at 4:05
  • @HarishKumar - I've deleted the 'article' tag and added the 'formatting' tag. You've got editing rights too, right?
    – Mico
    Sep 26, 2014 at 5:31
  • @Mico hehe!. I do certainly. But I don't use it well ;-)
    – user11232
    Sep 26, 2014 at 5:37

1 Answer 1

4

One way with sectsty:

\documentclass{article}
\usepackage{sectsty}
\sectionfont{\centering}
\begin{document}
  \section{Some section}
  \subsection{A subsection}
\end{document}

enter image description here

sectsty also offers \chapterfont (but in article class, there ain't no chapter), \subsectionfont etc along with \allsectionsfont which will apply to all sections.

With titlesec:

\documentclass{article}
\usepackage{titlesec}
\titleformat*{\section}{\Large\bfseries\centering}
\begin{document}
  \section{Some section}
  \subsection{A subsection}
\end{document}
5
  • Thanks. But they did not work for me; they both changed nothing :)
    – Yes
    Sep 26, 2014 at 5:44
  • @Comeseeconquer That is why we need to see your code ;-)
    – user11232
    Sep 26, 2014 at 5:47
  • Right, please see the edit.
    – Yes
    Sep 26, 2014 at 6:36
  • I was mistaken; it is alright now.
    – Yes
    Sep 26, 2014 at 6:43
  • titlesec didn't work for me here either btw, sectsty did though thanks
    – baxx
    Dec 14, 2015 at 19:05

You must log in to answer this question.

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