0

Right now I have a list of questions which I labeled.

\documentclass[10pt]{article}
\usepackage[hidelinks]{hyperref}
\usepackage{enumitem}

\begin{document}

    \newpage
    \section{Project}
    This is a researsch report.

    \subsection{Objective}
    Blablabla.

    \noindent\newline
    \large\textit{"Is this the main question?"}

    \noindent\newline
    sub questions:

    \begin{enumerate}[label=\textit{Q \roman*}, ref=\textit{Question \roman*}]
      \item \label{q1} {\normalsize\textit{"What is this question?"}}
      \item \label{q2} {\normalsize\textit{"Why is this a question?"}}
      \item \label{q3} {\normalsize\textit{"How is this a question?"}}
    \end{enumerate}
    \noindent

    \section{Research}
    Blablabla.

    \subsection{\ref{q1}: What is this question?}
    Blablabla.

    \subsection{\ref{q2}: Why is this a question?}
    Blablabla.

    \subsection{\ref{q3}: How is this a question?}
    Blablabla.

\end{document}

Which results in to:

enter image description here

Example: in overleaf.

The problem with this is that the subsection headers link to the list, and it would be more comprehensible that this would go the other way around. So that I label the headers and add an alternative counting in the headers and then generate a list out of this.

How to do this?

1

You can accomplish this using a new counter and \refstepcounter.

\documentclass[10pt]{article}
\usepackage[hidelinks]{hyperref}
\usepackage{enumitem}

% New counter for questions
\newcounter{question}
% Questions are labelled using lower case roman numerals
\renewcommand\thequestion{\roman{question}}

\begin{document}

    \newpage
    \section{Project}
    This is a researsch report.

    \subsection{Objective}
    Blablabla.

    \noindent\newline
    \large\textit{"Is this the main question?"}

    \noindent\newline
    sub questions:

    \begin{itemize}
      \item[Q \ref{what}]  {\normalsize\textit{"What is this question?"}}
      \item[Q \ref{why}]  {\normalsize\textit{"Why is this a question?"}}
      \item[Q \ref{how}]  {\normalsize\textit{"How is this a question?"}}
    \end{itemize}
    \noindent

    \section{Research}
    Blablabla.

    % Increment the question counter while also setting \ref to its value
    \refstepcounter{question}
    % Set "what" to \ref, which is the counter's value
    \label{what}
    % Use the counter's value for the subsection title
    \subsection{Question \thequestion: What is this question?}
    Blablabla.

    \refstepcounter{question}
    \label{why}
    \subsection{Question \thequestion: Why is this a question?}
    Blablabla.

    \refstepcounter{question}
    \label{how}
    \subsection{Question \thequestion: How is this a question?}
    Blablabla.

\end{document}

And instead of repeating those three lines for each subsection which answers a question, I would create a new command:

\newcommand\qsubsection[2]{
  \refstepcounter{question}
  \label{#1}
  \subsection{Question \thequestion: #2}
}

and then write, for instance,

 \qsubsection{what}{What is this question?}
    Blablabla.
  • Really good thanks, is there a possibility to automatically create a list of the counted items? As far as I know latex this is impossible because you need multiple runs, or at least it is possible with multiple runs. If you know how to do it please collaborate. – botenvouwer Apr 29 '19 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.