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.

Often I find myself in the situation that I'd like to design how chapters and sections look. I know there are packages that help to design such things, but non of them seems to give me the option to use the chapter/section number and the label as variables (like #1, #2).

Stefan has done something close to what I want in his blog using titlesec, but I was wondering:

Is there a pure LaTeX way of accessing the number and label of chapter/sections and use those in variables while I design a pagestyle?

share|improve this question
add comment

2 Answers

All the sectioning commands are in class (book, article report etc). Search in your distribution and look for book.cls.

They are quite lengthy and they are not in one place. For example all the "name" commands can be found towards the end of the class in one place.

Here is a minimal as to how to change some of the parameters.

\documentclass[oneside]{book}
\makeatletter
\renewcommand\chaptername{chapteris}
\renewcommand \thechapter {\@Roman\c@chapter}

\renewcommand\section{\@startsection{section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\large\scshape}}

\newcommand\sectionis{\@startsection{section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\large\scshape}}

\renewcommand\appendix{\par
  \renewcommand\chaptername{Appendixis}
  \setcounter{chapter}{0}
  \setcounter{section}{0}
  \gdef\@chapaa{\appendixname}
  \gdef\thechapter{\@roman\c@chapter}
 }

\makeatother
\begin{document}
  \tableofcontents
  \chapter{My First Chapter}
  \section{One}
  \sectionis{Two}
  \chapter{My Second Chapter}
  \appendix
  \chapter{First Appendix}
  \chapter{Second Appendix}
\end{document}
share|improve this answer
    
Thank you, I am however aware of those definitions. but the problem is, the definitions as in e.g. section ..{\normalfont\large\scshape}. Say I'd like to do something like \hspace{dim} section title \hspace{dim}, this is notpossible with this commands, is it? –  Martin H Feb 16 '11 at 9:51
    
If you really want this \hspace{dim}, you can use, for example : \def\@seccntformat#1{% \hspace*{<dim>}\protect\makebox[0pt][l]{\csname the#1\endcsname\quad}\hspace*{<otherdim>}% } –  Jhor Jul 13 '13 at 19:09
add comment

The current values are stored in the counters chapter, section, etc., so \thechapter gives you the formatted number and \arabic{chapter} always gives you the number, \roman{chapter} in roman numerals etc. (As Martin points out, \value{chapter} will contain the value as a "proper number".)

The titles... they might be in \leftmark and \rightmark, but that depends on the document class.

Is that what you are looking for?

share|improve this answer
    
I agree that the chapter and section counters store the right value, however \left/rightmark may not. Imagine a case where I use \chapter[short]{long}. I this case only the short title would be available in \leftmark –  Martin H Feb 14 '11 at 13:59
1  
You could add \value{chapter} which give the chapter number as, yeah, number, i.e. numeric expression usable in calculations. –  Martin Scharrer Feb 14 '11 at 14:09
    
I think I am fine with \thechapter or somethng similar, but how can I use the chapterlabel? dont need to reinvent the wheel and could use titlesec, but I thought there might be a another way... –  Martin H Feb 14 '11 at 15:32
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.