3

I would like Sections to display the subsection number,
but I feel that redefining \thesection will recursively affect \thesubsection.

Basically, we're looking to add a zero to the section number in headings and the table of contents.

Example:

What we currently get:

1.  Section 1   
1.1 Section 1, Subsection 1  
1.2 Section 1, Subsection 2  

What we're looking to get:

1.0 Section 1  
1.1 Section 1, Subsection 1  
1.2 Section 1, Subsection 2  

Additional info:

This post was a helpful start.

kando
  • 1,338

2 Answers2

2

Redefine \thesection to refer to subsection and \thesubsection to be the same as \thesection:

\documentclass{article}
\renewcommand{\thesection}{\arabic{section}.\arabic{subsection}}
\renewcommand{\thesubsection}{\thesection}

\begin{document}

\section{Section}

\subsection{First subsection}

\subsection{Second subsection}

\section{Section}

\subsection{First subsection}

\subsection{Second subsection}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Answer granted to @Elad Den for getting it in first. Still, I appreciate your efforts equally. Leave a comment for a little rep : j – kando Aug 02 '16 at 17:00
  • The indentations are off in the Table of Contents. Do you know any simple code to alleviate this? (Else I recommend checking this out.) Either way, can you modify your answer to include a solution? – kando Aug 02 '16 at 17:21
  • 1
    @kando You could make sections the same as subsections: the zero will tell the reader which is which. Tell me if the idea is what you want. – egreg Aug 02 '16 at 17:25
  • Oop. I didn't see the subtle difference between you two. Does this fix the ToC? (A peer is making the edits. He used \setlength{cftsecnumwidth}{+XXem} from package tocloft to make his fix.) – kando Aug 02 '16 at 17:28
  • 1
    @kando It's not clear whether you really want to repeat the section title in the subsection title. – egreg Aug 02 '16 at 17:40
  • I'm not sure that I understand your comment. I do not want to prepend the section label onto all of the subsection labels, if that is what you mean. [Edit: I think you may believe this because of my example in my original question. I was merely being articulate by labeling each section number in text. I did not intend for these to signify actual textual headings. (I used 'code' format to get everything to line up via monospace font).] – kando Aug 03 '16 at 14:37
1

Simply changing \thesection so that it would show whatever it is you want it after the number, then redefine \thesubsection so as not to call \thesection.

\documentclass{article}
\renewcommand{\thesection}{\arabic{section}.0}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}

\begin{document}
    \tableofcontents
    \medskip
    text text
    \section{test}
    nah
    \subsection{test1}
    blah
    \subsection{test2}
    jah
\end{document}

resulting in

just fixing the section

If you wish to fix the TOC you can use the tocloft package thus

\documentclass{article}
\usepackage{tocloft}


\renewcommand{\thesection}{\arabic{section}.0}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}
\renewcommand\cftsecnumwidth{2.5em}

\begin{document}
    \tableofcontents
    \medskip
    text text
    \section{test}
    nah
    \subsection{test1}
    blah
    \subsection{test2}
    jah
\end{document}

This would give you

TOC fix added

Elad Den
  • 3,941
  • The indentations are off in the Table of Contents. Do you know any simple code to alleviate this? (Else I recommend checking this out.) Either way, can you modify your answer to include a solution? – kando Aug 02 '16 at 17:20
  • Much thanks. All should note that the method proposed by egreg also works, (although it does not contain Elad Den's ToC fix at this time.) – kando Aug 03 '16 at 14:33