It's not convenient to include the counter in the second argument of \titleformat
; this will cause starred sections to be numbered in an "unorthodox" way, as the following simple example shows:
\documentclass{article}
\usepackage{titlesec}
\titleformat{\section}[block]{\large\scshape\centering{\Roman{section}.}}{}{1em}{}
\begin{document}
\section{Test Section}
\subsection{Test Subsection}
\section*{Test Section}
\subsection{Test Subsection}
\end{document}
This produces the following wrong result (the numbering is wrong, the spacing between the number and the title is wrong and the counter for subordinate sectional units isn't reset appropriately):
The right way to proceed here is to redefine \thesection
previously to use Roman numerals, as the following example illustrates:
\documentclass{article}
\usepackage{titlesec}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{test,
author= "The Author",
journal = "The Journal",
pages= "1-2",
year="2012"
}
\end{filecontents*}
\renewcommand\thesection{\Roman{section}}
\titleformat{\section}[block]
{\large\scshape\filcenter}{\thesection.}{1em}{}
\begin{document}
\section{test}
\cite{test}
\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}
If you want to number the bibliography section, you can use the etoolbox
package to patch the \thebibliography
command to use \section
instead of the default \section*
:
\documentclass{article}
\usepackage{titlesec}
\usepackage{etoolbox}
\usepackage{filecontents}
\patchcmd{\thebibliography}{\section*}{\section}{}{}
\begin{filecontents*}{\jobname.bib}
@article{test,
author= "The Author",
journal = "The Journal",
pages= "1-2",
year="2012"
}
\end{filecontents*}
\renewcommand\thesection{\Roman{section}}
\titleformat{\section}[block]
{\large\scshape\filcenter}{\thesection.}{1em}{}
\begin{document}
\section{test}
\cite{test}
\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}
Not related to the original problem but \centering
doesn't have arguments, so instead of \centering{text}
one should use something like {\centering text\par}
(the braces are only required if it is necessary to explicitly group to keep the effect local).
I think your best bet is to redefine \thesection
, which is the macro that normally prints the section number.
\renewcommand\thesection{}
If you want subsection numbers to include the section numbers that aren't getting printed, you will also need to redefine \thesubsection
, which normally calls \thesection
:
\makeatletter
\renewcommand\thesection{}
\renewcommand\thesubsection{\@arabic\c@section.\@arabic\c@subsection}
\makeatother
Best Answer
I don’ think there’s a finished macro/package for that but you can increment the counter either with
\stepcounter{section}
or with\refstepcounter{section}
which increments the counter and updates the belonging\ref
-lables.So If you need a command for this try
or if you’re using KOMA-Script
The main difference between
\section*
and\addsec
is that the latter also sets the headmarks and generates a ToC entry, where\section*
only prints text formatted like the section headline. (See the scrguien.pdf [or the german scrguide] for more information about\addsec
command)