7

I'm writing a document using the class article. There are some things I'd like to change, for example:

  • Always center \section and \subsection titles without doing it manually each time using \begin{center} ... \end{center}
  • decrease the spacing between list elements without writing \begin{enumerate}[itemsep=-1mm] each time.
  • etc.

Where can I find instructions about this? I couldn't find a "manual" where I could look up all of the options and keys. In case there is not a manual, how could I achieve these results?

Alenanno
  • 37,338
  • 3
    I'm afraid there's no comprehensive manual. The best approximation for a "do-it-all" is the documentation of memoir; indeed you can use memoir for an article. Simple changes to the section headings can be done with sectsty; more complex are done with titlesec. For lists the reference is enumitem (which you're already using). You might consult the "Breve guida" where some frequently used packages are described (in Italian). – egreg Jun 08 '12 at 09:17
  • @egreg I've seen some quesitons about titlesec, it looks kind of complicated but I guess I'll have to look into it deeper now... :) – Alenanno Jun 08 '12 at 09:22
  • 2
    I recommend to use the class scrartcl. It is well documented in the documentation scrguide (German) or scrguien (English). – Marco Daniel Jun 08 '12 at 09:23
  • @MarcoDaniel I tried looking for the English guide, but I got this message: "Note: you requested the material at a path /macros/latex/contrib/koma-script/scrguien.pdf that doesn't exist. This is the closest directory." Where is it? – Alenanno Jun 08 '12 at 09:32
  • @Alenanno: You can type texdoc scrguien – Marco Daniel Jun 08 '12 at 10:31
  • @Alenanno You surely can say texdoc scrguien on your system. However, the question, in the present form, doesn't seem to be answerable because it's too broad. – egreg Jun 08 '12 at 10:32
  • @egreg I was asking if there was an official manual, how is that broad? The answer is either "Yes here it is" or "No, there isn't one" or at worst "No there isn't one, but here is an alternative source...". – Alenanno Jun 08 '12 at 10:36
  • @egreg I could change it in order to ask only for those two things I mentioned. – Alenanno Jun 08 '12 at 10:37
  • @Alenanno your address for the doc on the web is out of date: try mirror.ctan.org:/macros/latex/contrib/koma-script/doc/scrguien.pdf – wasteofspace Jun 08 '12 at 11:47
  • For such things, ConTeXt beats LaTeX hands down. All commands are designed with easy configurability in mind. So, you can middle align all section heads by saying \setuphead[alternative=middle], decrease the spacing between items by saying \setupitemize[inbetween={\blank[small]}], etc. – Aditya Jun 08 '12 at 15:03
  • @Aditya yet another argument that drives me towards ConTeXt! – Gonzalo Medina Jun 08 '12 at 16:19

1 Answers1

10

For customizing sectional units you can use the sectsty package (for relatively "minor" changes) or the titlesec package; for customizing list-like environments, you can use the enumitem package; both enumitem and titlesec are very well documented and the documentations include numerous examples. Here's a little example illustrating the changes you mentioned in your question:

\documentclass{article}
\usepackage{titlesec}
\usepackage{enumitem}

\titleformat*{\section}{\centering\bfseries\Large}
\titleformat*{\subsection}{\centering\bfseries\large}

\setlist[enumerate]{itemsep=-1mm}

\begin{document}

\section{A test numbered section}
\begin{enumerate}
\item First item.
\item Second item.
\end{enumerate}
\subsection{A test numbered subsection}
\subsection*{A test unnumbered subsection}
\section*{A test unnumbered section}

\end{document}

enter image description here

The above approach applies mostly to standard document classes (book, article and report); other classes (memoir or the ones from the KOMA-Script bundle) have their own mechanisms; it should be noted, for example, that memoir or the KOMA-Script classes and titlesec are incompatible (See About memoir and titlesec incompatibility and Incompatibilities between KOMA-Script and titlesec).

Just for completeness's sake, I'll add one possible solution to both problems mentioned in the question but using the memoir document class. As I said before, now it's not advisable to use titlesec to customize the sectional unit headings, but to use the features provided by the class; I used the article class option and the prdedefined crosshead chapter style to get centered titles for sections (now produced using \chapter) and used \setsecheadstyle to center the subsection titles (now produced using \section); enumitem is still used to customize the enumerate environment:

\documentclass[article]{memoir}
\usepackage{enumitem}

\chapterstyle{crosshead}
\setsecheadstyle{\centering\bfseries\large}

\setlist[enumerate]{itemsep=-1mm}

\begin{document}

\chapter{A test numbered section}
\begin{enumerate}
\item First item.
\item Second item.
\end{enumerate}
\section{A test numbered subsection}
\section*{A test unnumbered subsection}
\chapter*{A test unnumbered section}

\end{document}

enter image description here

Using scrartcl from the KOMA-Script bundle, again using titlesec is not advisable, but you could use \sectfont instead:

\documentclass{scrartcl}
\usepackage{enumitem}

\renewcommand\sectfont{\centering\bfseries}
\setlist[enumerate]{itemsep=-1mm}

\begin{document}

\section{A test numbered section}
\begin{enumerate}
\item First item.
\item Second item.
\end{enumerate}
\subsection{A test numbered subsection}
\subsection*{A test unnumbered subsection}
\section*{A test unnumbered section}

\end{document}

enter image description here

As I used \sectfont, the changes will also affect subsubsections.

Finally, if you want to apply the changes to the amsart document class, you will only have to change the subsection formatting (section titles are centered by deafault in this class); the change can be done by redefining \subsection as implemented in amsart.cls, or using titlesec (as in the first example since titlesec is compatible with the AMS-family of document classes), or by patching this command with the help of, for example, the etoolbox package. A little example (lists have a more tight vertical spacing in this class so I left the modification commented):

\documentclass{amsart}
\usepackage{enumitem}

\makeatletter
\def\subsection{\@startsection{subsection}{2}%
  \z@{.5\linespacing\@plus.7\linespacing}{.5\linespacing}%
  {\normalfont\bfseries\centering}}
\makeatother
%\setlist[enumerate]{itemsep=-1mm}

\begin{document}

\section{A test numbered section}
\begin{enumerate}
\item First item.
\item Second item.
\end{enumerate}
\subsection{A test numbered subsection}
\subsection*{A test unnumbered subsection}
\section*{A test unnumbered section}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • The list command is not working, weird... I am using \usepackage[shortlabels]{enumitem} if it means something. – Alenanno Jun 08 '12 at 15:06
  • @Alenanno using the shortlabels option is not the cause of the problem (at least not with my example code); most probably you are using an outdated version of enumitem; the old syntax used \setenumerate, but this command is now deprecated and you should use the code as I posted it in my example. This is my version of enumitem (for comparison purposes): enumitem.sty 2011/09/28 v3.5.2 Customized lists. If outdated packages was not the problem, please edit your question adding a minimal, complete version of the problematic code. – Gonzalo Medina Jun 08 '12 at 16:03
  • Err I hate to be a newbie, but where do I check the package version? :D Thank you for your patience! – Alenanno Jun 08 '12 at 16:13
  • 1
    @Alenanno Add \listfiles somewhere in the preamble of your document; the only purpose of this command is to write a list of the files used and their versions in the output console and in the .log file. Process your document and then open the .log file and search for the section *File List*. – Gonzalo Medina Jun 08 '12 at 16:17
  • Oh, yes mine is v2.2... Maybe I should update all of my packages. :) – Alenanno Jun 08 '12 at 16:29
  • @Alenanno indeed! ;-) I've updated my answer showing a solution using memoir; if I have time I will also provide some code with scrartcl. – Gonzalo Medina Jun 08 '12 at 17:54
  • @Alenanno I added some code for scrartcl and amsart. – Gonzalo Medina Jun 08 '12 at 18:32