Are there some magic lines to be placed in the preamble that would, like in CSS, specify how each generic section or subsection in the whole document should be formatted?
[Tex/LaTex] Formatting each part/section/subsection
formattingsectioning
Related Solutions
With my comment in mind, here's a patch for \nameref
which will combine the names of two sectioning levels:
\documentclass{article}
\usepackage{nameref}
\makeatletter
\def\NR@gettitle#1{%
\GetTitleString{#1}%
\expandafter\let\csname @currentlabelname@\thesection@level\endcsname\GetTitleStringResult
\edef\@currentlabelname
{%
\ifcsname
@currentlabelname@\number\numexpr\c@section@level-\@ne\relax
\endcsname
\unexpanded\expandafter\expandafter\expandafter
{%
\csname
@currentlabelname@\number\numexpr\c@section@level-\@ne\relax
\endcsname
}%
\fi
\unexpanded\expandafter{\GetTitleStringResult}%
}
}
\makeatother
\begin{document}
\section{1}
\label{sec:1}
\subsection{a}
\label{sec:1a}
section: \nameref{sec:1}.
subsection: \nameref{sec:1a}.
\end{document}
I hope it is clear that this is not very general, but it answers your exact question. It sould be possible to generalize it further.
Edit
Patch when titlesec
is used...
\usepackage{etoolbox}
\makeatletter
\def\chapter@level{0}
\def\section@level{1}
\def\subsection@level{2}
\def\subsubsection@level{3}
\def\paragraph@level{4}
\def\subparagraph@level{5}
\patchcmd\ttl@straight@i{\def\@currentlabelname{#2}}
{%
\expandafter\def
\csname @currentlabelname@\csname#1@level\endcsname\endcsname{#2}%
\edef\@currentlabelname
{%
\ifcsname
@currentlabelname@\number\numexpr\csname#1@level\endcsname-\@ne\relax
\endcsname
\unexpanded\expandafter\expandafter\expandafter
{%
\csname
@currentlabelname@\number\numexpr\csname#1@level\endcsname-\@ne\relax
\endcsname
}%
\fi
\unexpanded{#2}%
}
}{}{}
\makeatother
This is readily achievable using sectsty
and some manual adjustments for the \chapter
setting:
\documentclass{report}
\usepackage{sectsty}
% http://tex.stackexchange.com/q/59726/5764
\allsectionsfont{\centering\normalsize\bfseries}% All sections are centred/normal size/bold
\subsectionfont{\normalsize\bfseries}% Correct \subsection formatting
\renewcommand{\thechapter}{\Roman{chapter}}% Chapter number formatting
\renewcommand{\thesection}{\thechapter.\roman{section}}% Section number formatting
% http://tex.stackexchange.com/q/42161/5764
\setcounter{secnumdepth}{1}% Only number up to \section
\makeatletter
% http://tex.stackexchange.com/q/24439/5764
\renewcommand{\@seccntformat}[1]{\csname the#1\endcsname.~}% Add period after section number in title
% Taken from http://mirrors.ctan.org/macros/latex/contrib/sectsty/sectsty.dtx
\def\@makechapterhead#1{%
\vspace*{2in}% Formerly \vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
%\ifnum \c@secnumdepth >\m@ne
% \huge\bfseries\SS@chapnumfont{\@chapapp\space \thechapter}%
% \par\nobreak
% \vskip 20\p@
%\fi
\interlinepenalty\@M
%\raggedright \normalfont
\Huge \bfseries \SS@chaptitlefont {\thechapter.~#1}\par\nobreak
\vskip 40\p@
}}
\makeatother
\begin{document}
\chapter{A chapter}
Some text in this chapter.
\section{A section}
Some text in this section.
\subsection{A subsection}
Some text in this subsection.
\end{document}
The 2" margin for \chapter
-pages only is measured from the top of the text block. As such, the regular text block margins relative to the page still remains.
References to other questions relating to the above changes are scattered within the code.
Best Answer
You can use the
titlesec
package for this.A short example would be
\titleformat*{\section}{\itshape}
to change the style of\section
to\itshape
. See the package manual for more details.See also:
What's the right way to change display of chapter headings?
How to format the chapter heading?
Formatting a \paragraph to look like a \section
or questions tagged with titlesec.