10

For a paper I have to make my LaTeX document guideline conforming. Many of you will already guess now that this means dirty work by violating virtually all possible typography standards.

My biggest problem is concerning section headings. They have to be:

  • Capitalized
  • Underlined
  • Centered
  • Have roman numerals
  • The bibliography should not be appended a section number.

I tried to achieve this using the sectsty package and since that did not work out gave the titlesec package a shot, both with and without the ulem package.
However, no combination worked. The problem occurs in any way when you give the option underlined.

Here is a minimal example with the sectsty package:

\documentclass{scrartcl}

\usepackage{ucs}
\usepackage[utf8x]{inputenc}

%% ADJUSTMENTS FOR IAC
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Get stupid underlining for headings right
\usepackage[]{ulem}

%% Change heading style
\usepackage{sectsty}
    \sectionfont{\MakeUppercase\rmfamily\center\underline}

\begin{document}
    \section{Test Section}
\end{document}

How can I make those headings conform to the rules? Would it probably even be the easiest way to manually write the headings, without a command at all?

  • Are you allowed to fiddle with the sectioning command and/or include packages as needed? I know that some journal restrict the use of external packages, or have a list of "approved packages" that you can use. – Werner Aug 29 '11 at 16:09
  • Yes I am, all I have to do is hand in a PDF. – Ingo Aug 29 '11 at 16:16
  • 1
    I think this question deserves the starred-version tag. I had to drop another tag and chose sectsty. – lockstep Sep 3 '11 at 11:22
  • Quoting from page 5 of the manual of the sectsty package: "The documentation for this package is written with the standard LATEX classes in mind, so might not [tee] up exactly to the KOMA-script classes. Despite that, and despite differences in behaviour when things go wrong, sectsty should work as expected with the KOMA-script classes." I guess you're encountering an instance when this isn't the case... – Mico Sep 3 '11 at 17:22
  • On second thought, this question is also not specific to koma-script, but shows how to solve a horizontal-alignment problem. – lockstep Sep 3 '11 at 23:30
15
+50

Building on Gonzalo's answer: Use the numberless key to define the starred version of \section.

\documentclass{scrartcl}

\usepackage[explicit]{titlesec}
\usepackage[normalem]{ulem}
\usepackage{lipsum}

\titleformat{\section}
  {\normalfont\Large\sffamily\bfseries\filcenter}{}{0em}{\uline{\thesection\hspace*{ 1em}\MakeUppercase{#1}}}
\titleformat{name=\section,numberless}
  {\normalfont\Large\sffamily\bfseries\filcenter}{}{0em}{\uline{\MakeUppercase{#1}}}

\renewcommand*{\thesection}{\Roman{section}}

\begin{document}

\section{Test Section}

\lipsum[1]

\begin{thebibliography}{9}
\bibitem{A01} A. Author. \emph{Alpha}. 2001.
\end{thebibliography}

\end{document}

enter image description here

  • 1
    @Ingo: Note that upvoting, accepting, and awarding bounty all have to be done separately. – lockstep Sep 4 '11 at 8:34
  • I'm sorry, must have forgotten that in a rush :). – Ingo Sep 4 '11 at 9:58
  • A rush of happiness, I presume. :-) – lockstep Sep 4 '11 at 9:58
  • @Ingo: Thanks for awarding the bounty to me, but I think that Gonzalo Medina's latest edit makes his answer the better one, and that you should accept it instead of mine. – lockstep Sep 9 '11 at 15:57
  • This doesn't work for me. I just get the error "! Argument of \@xdblarg has an extra }." – Marcin Nov 11 '12 at 18:38
14

Here's a simple solution using the ulem package and the explicit option for titlesec:

\documentclass{scrartcl}

\usepackage[explicit]{titlesec}
\usepackage[normalem]{ulem}
\usepackage{lipsum}

\titleformat{\section}
  {\normalfont\Large\sffamily\bfseries\filcenter}{\uline{\thesection\hspace*{ 1em}}}{0em}{\uline{\MakeUppercase{#1}}}

\renewcommand*{\thesection}{\Roman{section}}

\begin{document}
\section{Test Section}

\lipsum[1]

\begin{thebibliography}{9}
\bibitem{A01} A. Author. \emph{Alpha}. 2001.
\end{thebibliography}

\end{document}

enter image description here

  • Nice and clean solution - the explicit package option is the key here. – Werner Aug 29 '11 at 18:01
  • I thank you very much, Gonzalo! Whatever it takes to comply with those ... nice ... requirements. – Ingo Aug 30 '11 at 10:16
  • One more question, though. Why do prefer titlesec over sectsty? – Ingo Aug 30 '11 at 10:47
  • 3
    @Ingo Gerth: with the explicit option for titlesec one has access to the title as a parameter, so it is easy to apply \ulem to it. – Gonzalo Medina Aug 30 '11 at 11:44
  • 1
    Gonzalo, thank you very much again. However, it so happens that this causes the bibliography to have a section number, whereas it should not. You can easily try this out. Is there any workaround for this? – Ingo Sep 3 '11 at 10:54
3

Because both the answer provided by Gonzalo and the answer provided by lockstep don't work well, here is mine. This might be grave diggin' because the original question is 5 years old but it shows up at the top of google. The problem with both of their solutions is, that the entire caption is in one hbox. Because of that long captions do not work. They get an overfull hbox. My solution only addresses that and doesn't address the rest of the question (capitalized captions and stuff). In addition my solution does not work with KOMA-script-classes.

\documentclass{article}

\usepackage[normalem]{ulem}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{sectsty}

\allsectionsfont{\sffamily\underline}
\titleformat{\section}
{\normalsize\bfseries\raggedright}
   {\llap{\makebox[3mm][l]{\thesection}}}
   {0em}
   {}

\begin{document}
\section{This is a really long section heading and I'm proud of it}
\lipsum[1]
\end{document}

EDIT: For a KOMA compatible way to allow line breakable underlined headings see this answer.

EDIT2: If you use KOMA and hyperref, the above provided link doesn't work if you use \tableofcontents or similar, so you might take a look at this other answer.

  • There seems to be no need for \makebox[3mm][l] here. – Werner Oct 23 '16 at 19:02
  • Note: You should not longer use titlesec with scrartcl. – Schweinebacke Jun 28 '17 at 10:23
  • @Schweinebacke I know and I don't. There is no scrartcl in my answer, it clearly states, that it is not compatible with KOMA and the EDIT links to an answer which is and doesn't use titlesec, so what is the problem? – Skillmon Jun 28 '17 at 11:55
  • My comment was, because the example in the question has used scrartcl. – Schweinebacke Jun 28 '17 at 13:11
  • @Schweinebacke and I linked to a working answer which uses KOMA-classes and does the job better than all the answers provided here (including yours). Well the answer in the link suffers its own problems (hyperref compatibility). I'll edit my answer providing a link to another answer incorporating hyperref. – Skillmon Jun 28 '17 at 14:21
2

For several years usage of titlesec with KOMA-Script classes is not recommended or only recommended if you do not need extended headings features of the KOMA-Script classes. So I would recommend to use scrartcl's interface to change the section heading:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}

\usepackage[]{ulem}
\usepackage{microtype}% to add letter spacing

\addtokomafont{section}{\rmfamily\lsstyle}% use roman instead of sans serif
                                % but letter spaceing
\renewcommand*{\sectionlinesformat}[4]{%
  \ifstr{#1}{section}{% do it only, for section level
    \centering \uline{#3\MakeUppercase{#4}}%
  }{%
    \@hangfrom{\hskip #2#3}{#4}% otherwise use the default
  }%
}

\usepackage{blindtext}

\begin{document}
\section{Test Section}
\blindtext
\section*{Test Section}
\blindtext
\addsec{Test Section}
\blindtext
\end{document}

enter image description here

Here I've used \addtokomafont to change the font of the heading and also to add some automatic letter spacing (because of the upper case typesetting) and redefined \sectionlinesformat to add \MakeUppercase, \uline and \centering. If not only the section but also sub-section etc. titles should be centered. You could get centering also using \let\raggedsection\centering. Nevertheless, \sectionlinesformat should be used for \MakeUppercase and \uline in that case too.

-1
\documentclass{article} 
\usepackage{fontspec}
\usepackage{lipsum}

\begin{document} 
\thispagestyle{empty} 
\font\uc="Times New Roman" at 12pt
\begin{center}
\underbar{\uc{But it may be enough to get you started, at least. }}
\end{center}
\lipsum[1]

\begin{thebibliography}{9}
\bibitem{A01} A. Author. \emph{Alpha}. 2011.
\end{thebibliography}

\end{document}
  • 1
    You forgot to load lipsum (I did it in my edit) and loaded some irrelevant packages (I deleted them). Notice that your solution doesn't number the sections and doesn't allow for labelling. You should also mention (although fontspec makes it clear) that your code needs to be run with xelatex. – Gonzalo Medina Sep 9 '11 at 13:17
  • And this code does not prevent page breaks between the pseudo heading an the text. – Schweinebacke Jun 28 '17 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.