3

I want to write a report, where each chapter has the same structure. e.g. the first section is always pros, the second is cons, the third is opinions and the fourth section is the final conclusion. Currently, I'm using the following pattern:

\chapter{Report title}
\section{Pros}
pros here
\section{Cons}
cons here
\section{Opinions}
opinions here
\section{Conclusion}
conclusion here

I have to repeat this pattern for every report.

Is there a way to customise the document such that the first section of a chapter always says "Pros", second "Cons", etc?

So I can just do:

\chapter{Report title}
\section{}
pros here
\section{}
cons here
\section{}
opinions here
\section{}
conclusion here

3 Answers 3

1

@Rizhiy Is this Ok?

\documentclass[10pt]{book}

\newcommand\pros{\section*{Pros}}
\newcommand\cons{\section*{Cons}}
\newcommand\opinion{\section*{Opinions}}
\newcommand\conclusion{\section*{Conclusion}}

\begin{document}
\chapter{Report title}

\pros
pros here
\cons
cons here

\opinion
opinions here

\conclusion
conclusion here

\end{document}
1
  • I think the OP wanted to automate things such that a single \nextsection would automatically print Pros/Cons/Opinions/Conclusion according to the value of \thesection
    – Dai Bowen
    Dec 14, 2016 at 15:45
3

Perhaps the following does as you'd like; the idea is to copy the definition of the original \section command, and then redefine the section command depending upon the value of the section counter.

I've set up values for Pros (1), Cons (2), Opinions (3), Conclusions (4), and then to use the second argument of \section as default. This approach also allows you to pass an optional first argument for the toc, as demonstrated.

% arara: pdflatex
% arara: pdflatex
\documentclass{report}

\let\oldsection\section

\renewcommand{\section}[2][]{%
    \ifcase\value{section}
    \def\mystring{Pros}
    \or
    \def\mystring{Cons}
    \or
    \def\mystring{Opinions}
    \or
    \def\mystring{Conclusions}
    \else
    \def\mystring{#2}
    \fi
    % if #1 is empty, use \mystring in the toc
    \ifx\\#1\\
    \oldsection[\mystring]{\mystring}
    \else
    % otherwise use #1
    \oldsection[#1]{\mystring}
    \fi
}

\begin{document}
\tableofcontents
\chapter{Report title}
\section{}
pros here
\section{}
cons here
\section[something else for the toc]{}
opinions here
\section{}
conclusion here
\section{}
other
\end{document}
1

If every chapter will have four sections and each section should be titled Pros, Cons, Opinions, Conclusions then you could automate things with a single command which prints a command according to the value of \thesection counter (as long as \thesection is less than four, otherwise it does nothing, maybe it should be made to throw an error or similar if \thesection has value four or greater).

\documentclass{report}
\newcommand\nextsection{
    \ifnum\value{section}=3\section{Conclusions}\fi
    \ifnum\value{section}=2\section{Opinions}\fi
    \ifnum\value{section}=1\section{Cons}\fi
    \ifnum\value{section}=0\section{Pros}\fi
}

\begin{document}
\chapter{Report Title}
\nextsection
Pros
\nextsection
Cons
\nextsection
Opinions
\nextsection
Conclusions
\end{document}

enter image description here

Although I suspect it may be better practise to manually enter the \section commands with appropriate argument as it's less likely to lead to an accidentally mis-named section.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .