Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want the title for the Acknowledgements page in my thesis to be in small caps. However, if I change it, it also changes in the table of contents. ToC

How can I avoid this? Especially, the roman page number in the ToC is in small caps too, even if on the page it is in normal small letters. What I would like is to have the entry for Acknowledgements look the same way that the entry for Abstract does. Here a minimal example:

\documentclass[a4paper, titlepage]{article} 

\let\stdsection\section 
\renewcommand\section{\newpage\stdsection}

\begin{document}

\pagenumbering{roman}

\setcounter{secnumdepth}{0}

\begin{center}
\section{\sc{Acknowledgements}} 
Thanks
\end{center}

\section{Abstract} 
Abstract text

\tableofcontents

\cleardoublepage
\setcounter{page}{1}
\pagenumbering{arabic}

\section{Introduction}
Blablabla

\end{document}
share|improve this question
    
For the way in which you are using, why don't you just put \section[Acknowledgements]{\sc{Acknowledgements}}? –  Harish Kumar Apr 25 '12 at 4:26
add comment

5 Answers

up vote 10 down vote accepted

\titleformat* (from the titlesec package) can be used in the body of the document; using a grouping mechanism, you can keep the effect local. In the example below I wrapped the format definition inside a command using a group to modify the aspect of only the desired sectional unit:

\documentclass[a4paper, titlepage]{article} 
\usepackage{titlesec}

\setcounter{secnumdepth}{0}

\newcommand\SpSection{%
  \titleformat*{\section}{\centering\scshape\Large}
}

\begin{document}

\pagenumbering{roman}

\begingroup
\SpSection
\section{Acknowledgements}
Thanks
\endgroup

\section{Abstract} 
Abstract text

\tableofcontents

\end{document}

enter image description here

share|improve this answer
    
If I do it this way, how can I set the fontsize of the small caps title to the "normal" title size? –  Helen Apr 23 '12 at 17:46
    
@Helen I've updated my answer with a simplified version. –  Gonzalo Medina Apr 23 '12 at 18:58
    
@GonzaloMedina: What happens to \noindent within and after the group? You may want to allow the user to insert \noindent his/herself after the section heading. Or offer options for code before and after the section heading. –  Ahmed Musa Apr 23 '12 at 19:26
    
@AhmedMusa: you're right. I've updated my answer. Thank you. –  Gonzalo Medina Apr 23 '12 at 19:54
    
@GonzaloMedina: You've changed too much. I have illustrated what I meant in my solution. –  Ahmed Musa Apr 25 '12 at 0:36
show 1 more comment

For this simple requirement, the sectsty package can be useful:

\documentclass[a4paper, titlepage]{article}
\usepackage{sectsty}
\newcommand\specialsection[2][\bfseries]{%
  \sectionfont{\normalfont#1}\section*{#2}
  \addcontentsline{toc}{section}{#2}
  \sectionfont{}}

\begin{document}

\pagenumbering{roman}

\specialsection[\centering\scshape]{Acknowledgements}
Thanks

\specialsection{Abstract}
Abstract text

\tableofcontents

\cleardoublepage

\pagenumbering{arabic}

\section{Introduction}
Blablabla

\end{document}
share|improve this answer
add comment

If you want a little more control you need to define your own macros. To define a sectioning command you can use:

\newcommand\prematter@sp[1]{% 
    %\refstepcounter{section}% we do not need to step up the counter
    \addcontentsline{toc}{section}% generate toe entry
     {\protect\numberline{}\textsc{#1}}%
     \sectionmark{#1}% % add to running header
     {\clearpage\LARGE\centering\bfseries \MakeUppercase{#1}\par}%
     \@afterheading % prepare indentation handling
     \addvspace{\baselineskip}
     \@afterindentfalse % comment out if you want to indent first paragraph
  }

Then it is preferable to define an environment named say \prematter

\newenvironment{prematter}[1]{%
   \prematter@sp{#1}}
{}

Here is a full MWE,

\documentclass[a4paper, titlepage]{book} 
\usepackage{lipsum}
\makeatletter
\newcommand\prematter@sp[1]{% % Complex form:
%\refstepcounter{section}% % step counter/ set label
\addcontentsline{toc}{section}% % generate toe entry
{\protect\numberline{}\textsc{#1}}%
\sectionmark{#1}% % add to running header
{\clearpage\LARGE\centering\bfseries \MakeUppercase{#1}\par}%
\@afterheading % prepare indentation handling
\addvspace{\baselineskip}
}
\newenvironment{prematter}[1]%
{%
   \prematter@sp{#1}}
{}
\makeatother
\begin{document}
\setcounter{secnumdepth}{0}
\frontmatter
\begin{prematter}{Acknowledgements}
\lipsum[1]
\end{prematter}
\begin{prematter}{Abstract} 
\lipsum[1]
\end{prematter}
\tableofcontents
\end{document}
share|improve this answer
add comment

You can use \addcontentsline and the starred version of \section*, like this:

\section*{\sc{Acknowledgements}%
\addcontentsline{toc}{section}{Acknowledgements}%

But I wouldn't recommend applying formatting (like \sc) to the section heading, since the best advantage os LaTeX and friends over document editors is its capability of keeping format and content separated.

So, if you have a special "acknowledgments" section, you should define it in the preamble and call it in the text; a (not so) simple solution is to copy the \section definition from article.cls and redefine it to the expected behavior. Something like this:

\makeatletter% This is needed to allow usage of the @ character 
\newcommand{\acknowledgements}{%
%  First we need to redefine the \section command formatting
  \begingroup%  This is needed to avoid the redefinition of \section to interfere with subsequent sections
    \renewcommand\section{%                        _
      \@startsection {section}{1}{\z@}%             |   This comes form the definition of
      {-3.5ex \@plus -1ex \@minus -.2ex}%           |   \section in article.cls
      {2.3ex \@plus.2ex}%                          _|
      {\centering\normalfont\Large\scshape}}%           added \centering and \scshape
%    Then we create a macro that 
%      1. Creates a starred \acknowledgements with the title "acknowledgements"; and
%      2. adds the starred version of \acknowledgements to the toc
  \section*{Acknowledgements}%
  \addcontentsline{toc}{section}{Acknowledgements}%
  \endgroup}
\makeatother% Turns @ back into a special char

For a more friendly control over sectioning commands, you can use the titlesec package, as I had mentioned in the prevous version of my answer, and as in @Gonzalo Medina's answer.

share|improve this answer
    
The thing is that I only want one of the titles to be in small caps. All the others should look normal. –  Helen Apr 23 '12 at 13:48
    
henrique gave two answers (and blocks of code). The first one should only alter the formatting for a single section. The second one looks like a suggestion. –  JohnReed Apr 23 '12 at 14:21
    
I just realized that it looks much better if I use \textsc instead of \sc and doesn't affect the page numbers in the ToC. So I just use that. With the first answer, in the ToC I get a page number that is by one lower than where the title of the section actually is (I have each section on a new page). –  Helen Apr 23 '12 at 15:03
2  
@Helen The first answer should have the command order reversed; I think that the \addcontentsline command should be after the \section* command. –  JohnReed Apr 23 '12 at 17:35
    
@Helen, I have edited my answer to try to be more clear about separating content and fomatting; @JohnReed's absolutely right twice, particularly, about the order of \addcontentsline (my bad). Please notice @GonzaloMedina's answer for a solution with titlesec –  henrique Apr 23 '12 at 17:50
add comment

Expanding on Gonzalo Medina's solution:

\documentclass[a4paper, titlepage]{article}
\usepackage{titlesec}
\usepackage{ltxkeys}
\makeatletter
\ltxkeys@declarekeys[KV]{spsection}[sps@]{%
  cmd/code before;
  cmd/code after;
  cmd/heading properties;
  cmd/heading type/section;
  cmd/heading text;
  bool/no heading no/true;
  cmd/label//
    \ifltxkeys@dec\else
      \ifx\\#1\\\@latexerr{Label can't be empty}\@ehd\fi
    \fi;

}
\robust@def*\spsection{\@testopt\@spsection{}}
\new@def\@spsection[#1]{%
  \saverestoresecnumdepth0%
  \usename{sps@no heading nofalse}%
  \ltxkeys@setkeys[KV]{spsection}{#1}%
  \csname sps@code before\endcsname
  \begingroup
  \ifboolFT{sps@no heading no}{}{%
    \setcounter{secnumdepth}{0}%
  }%
  \cptexpandsecond{\titleformat*}{%
    {\expandafter\expandafter\expandafter\expandafter
    \expandafter\expandafter\expandafter\noexpand
    \expandafter\expandafter\expandafter
      \csname\csname sps@heading type\endcsname\endcsname
    }{\expandcsnonce{sps@heading properties}}%
  }%
  \ifcsnnullFT{sps@heading text}{}{%
    \@@warning{Heading text was empty when calling \string\spsection}%
  }%
  \cptexpanded{\noexpand\usename{\expandcsnonce{sps@heading type}}%
    {\expandcsnonce{sps@heading text}}}%
  \endgroup
  \ifx\sps@label\@empty\else
    \label{\sps@label}%
  \fi
  \saverestoresecnumdepth{1}%
  \futurelet\next\doendcode@a
}
\robust@def*\doendcode@a{%
  \ifx\next\@sptoken
    \expandafter\doendcode@b
  \else
    \csname sps@code after\expandafter\endcsname
  \fi
}
\lowercase{\def\doendcode@b} {\usename{sps@code after}}
\robust@def*\saverestoresecnumdepth#1{%
  \ifcase#1\relax
    \edef\savedsecnumdepth{\the\c@secnumdepth}%
  \or
    \c@secnumdepth\savedsecnumdepth\relax
  \fi
}
\makeatother

% Tests
\begin{document}
\paperheight=5cm
\pagenumbering{roman}

\spsection[
  label              =sec:first,
  heading type       =section,
  heading text       =Acknowledgment,
  heading properties =\centering\scshape\Large,
  no heading no      =true,
  code before        =\noindent Last section is~\ref{sec:last}
                        on page~\pageref{sec:last}.,
  code after         =\noindent,
]
Thanks

\section{Abstract}
Abstract text.

\tableofcontents
\newpage

\pagenumbering{arabic}
\section{Test section}
Some text.
\newpage

\section{Another test section}
Some text.

\spsection[
  heading type       =subsection,
  heading text       =Test subsection,
  heading properties =\scshape\large,
  code before        =\endgraf\noindent First section is
                        on page~\pageref{sec:first}.,
  label              =sec:last
]

Some text.
\end{document} 
share|improve this answer
    
Ah! Now I see what you meant; effectively, I misunderstood your comment to my answer. Nice solution, by the way. –  Gonzalo Medina Apr 25 '12 at 0:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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