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}
2
  • This shouts at you: Use a redefinition of the \section command ;-)
    – user31729
    Jun 1, 2016 at 18:02
  • @ChristianHupfer I saw tex.stackexchange.com/questions/164333/… but I don't need comment for each subsection
    – hola
    Jun 1, 2016 at 18:03

1 Answer 1

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}
4
  • Well, what to do if I want a comment even for starred sections?
    – hola
    Jun 1, 2016 at 18:22
  • @pushpen.paul: \latex@@section*{#3\hfill\textit{#4}} (and similar for subsection then
    – user31729
    Jun 1, 2016 at 18:23
  • Great, thanks. I adjusted with \normalfont\normalsize.
    – hola
    Jun 1, 2016 at 18:26
  • @pushpen.paul: Of course, that's your choice
    – user31729
    Jun 1, 2016 at 18:29

You must log in to answer this question.

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