5

I want to write a statement about the current status of some topics (which are in sections/subsections) right aligned with the corresponding section/subsection title. For example, see the figure:

I did this with: \section{Zeroth Topic} \vspace*{-2.25em} \hfill \textit{Not started} \\ Some text goes here.

But what is a simpler way? I need such status statements against some of the section/subsection titles. Here's a minimal working example to start with:

\documentclass{article}

\begin{document}

    \section{Zeroth Topic} \vspace*{-2.25em} \hfill \textit{Not started} \\
    Some text goes here.

    \section{First topic}       \textit{Completed}
    Some text goes here.

    \section{Second topic}      \textit{Not started}
    Some text goes here.

    \section{Third topic}       % no comment
    Some text goes here.

    \section{Fourth topic}      % no comment
    Some text goes here.

        \subsection{First Subtopic}     \textit{Minor progress}
        Some text goes here.

        \subsection{Second Subtopic}            % no comment
        Some text goes here.

\end{document}
hola
  • 4,026
  • 3
  • 35
  • 72
  • This shouts at you: Use a redefinition of the \section command ;-) –  Jun 01 '16 at 18:02
  • @ChristianHupfer I saw http://tex.stackexchange.com/questions/164333/subsection-starting-in-same-line-as-subsection-name but I don't need comment for each subsection – hola Jun 01 '16 at 18:03

1 Answers1

5

This feature can be added easily using an 2nd optional argument to the \section and \subsection commands, which is used for the 'status'.

This does no harm if the argument is empty.

\documentclass{article}

\usepackage{xparse}

\makeatletter
\let\latex@@section\section
\let\latex@@subsection\subsection




\RenewDocumentCommand{\section}{somO{}}{%
  \IfBooleanTF{#1}{% Is it the starred version (s)?
    \latex@@section*{#3}%
  }{% Nope
    \IfValueTF{#2}{% Is the 2nd optional argument in action?
      \latex@@section[#2]{#3\hfill\textit{#4}}
    }{% No 2nd optional argument, write `#3` to the ToC instead.
      \latex@@section[#3]{#3\hfill\textit{#4}}
    }%
  }%
}

\RenewDocumentCommand{\subsection}{somO{}}{%
  \IfBooleanTF{#1}{%
    \latex@@subsection*{#3}%
  }{%
    \IfValueTF{#2}{%
      \latex@@subsection[#2]{#3\hfill\textit{#4}}
    }{%
      \latex@@subsection[#3]{#3\hfill\textit{#4}}
    }%
  }%
}


\makeatother

\begin{document}
\tableofcontents

    \section{Zeroth Topic}[Not started]
    Some text goes here.

    \section{First topic}[Completed]
    Some text goes here.

    \section{Second topic}[Not started]
    Some text goes here.

    \section{Third topic}       % no comment
    Some text goes here.

    \section{Fourth topic}      % no comment
    Some text goes here.

    \subsection{First Subtopic}[Minor progress]

    Some text goes here.

    \subsection{Second Subtopic}
    Some text goes here.
\end{document}

enter image description here

Update

A version which allows switching off status content:

\documentclass{article}

\usepackage{xparse}

\makeatletter
\let\latex@@section\section
\let\latex@@subsection\subsection

\newif\ifusestatus

\usestatustrue




\RenewDocumentCommand{\section}{somO{}}{%
  \IfBooleanTF{#1}{%
    \latex@@section*{#3}%
  }{%
    \ifusestatus
    \edef\@@tempa@@{#4}
    \else
    \edef\@@tempa@@{}
    \fi
    \IfValueTF{#2}{%
      \latex@@section[#2]{#3\hfill\textit{\@@tempa@@}}
    }{%
      \latex@@section[#3]{#3\hfill\textit{\@@tempa@@}}
    }%
  }%
}

\RenewDocumentCommand{\subsection}{somO{}}{%
  \IfBooleanTF{#1}{%
    \latex@@subsection*{#3}%
  }{%
    \ifusestatus
    \edef\@@tempa@@{#4}
    \else
    \edef\@@tempa@@{}
    \fi
    \IfValueTF{#2}{%
      \latex@@subsection[#2]{#3\hfill\textit{\@@tempa@@}}
    }{%
      \latex@@subsection[#3]{#3\hfill\textit{\@@tempa@@}}
    }%
  }%
}


\makeatother

\begin{document}
\tableofcontents

    \section{Zeroth Topic}[Not started]
    Some text goes here.

    \section{First topic}[Completed]
    Some text goes here.

    \section{Second topic}[Not started]
    Some text goes here.

    \section{Third topic}       % no comment
    Some text goes here.

    \section{Fourth topic}      % no comment
    Some text goes here.

    \subsection{First Subtopic}[Minor progress]

    Some text goes here.

    \subsection{Second Subtopic}
    Some text goes here.
\end{document}