0

I'd just defined a command, as below:

\newcommand{\Question}[1]{\textbf{?: #1}\\[5pt]}

Here is the snippet, in that I want to use an itemzie environment:

\documentclass[letter, 11pt]{article}

\newcommand{\Question}[1]{\textbf{?: #1}\\[5pt]}

\begin{document}

\section*{Question \#2}
\Question{Here is the question
\begin{itemize}
    \item[2.1] first part
    \item[2.2] second part
\end{itemize}
}

\end{document}

The compilation raises an error, as:

There's no line here to end.

So, as I add a character just at the end of the itemize environment, the error will be disappeared:

\Question{Here is the question
\begin{itemize}
    \item[2.1] first part
    \item[2.2] second part
\end{itemize}
.
}

Seemingly, the definition of Question command should be changed, but I don't know how I should do that.

7
  • the posted code does not make the error that you ask about but ! LaTeX Error: There's no line here to end. which is a different message because of a different error, which did you want to ask about? Oct 17, 2016 at 7:48
  • 1
    Use {\bfseries#1} instead of \textbf{}. But i find a bit weird to have the whole uestion bold faced.
    – Johannes_B
    Oct 17, 2016 at 7:50
  • @DavidCarlisle: Sorry, I just made a mistake to reflect the error type. Please find the applied edit.
    – User
    Oct 17, 2016 at 7:50
  • 1
    Add vertical spaace using \vspace{5pt}.
    – Johannes_B
    Oct 17, 2016 at 7:51
  • I think an environment for the questions would be much better than a command.
    – Johannes_B
    Oct 17, 2016 at 7:52

2 Answers 2

4

The whole construct would certainly be better as an environment. \textbf does not allow blank lines (which relates to an earlier version of the question) and use of \\ is almost never wanted outside tables. here if #1 does not end mid-paragraph then you will get an error from \\ saying that there is no line to end, you should use \par\vspace{5pt} or better use a display environment based on list so that space from adjacent displays is better handled.

But a simple redefinition would be

\newcommand{\Question}[1]{{\bfseries?: #1\par\vspace{5pt}}}
4

I think that a command is useless here. And the manual numbering will drive you insane. Put it in a nice environment and let LaTeX do the job.

\documentclass[11pt]{article}

\setcounter{secnumdepth}{-1}
\newcounter{question}
\newenvironment{question}{\refstepcounter{question}\section{Question \thequestion}\bfseries{?:~}}{\par\vspace{5pt}}
\usepackage{enumitem}
\newlist{qitemize}{enumerate}{2}
\setlist[qitemize]{label={\thequestion.\arabic*}}

\begin{document}

\begin{question}What is a cool animal?
    \begin{qitemize}
        \item first wombat
        \item second capybara
    \end{qitemize}
    \end{question}
\begin{question}What is a tasty fruit?
    \begin{qitemize}
        \item Banana
        \item Lemon
    \end{qitemize}
    \end{question}

\end{document}

roboticistNoLineToEnd

Personally, i consider the whole question bold as extremely ugly.

3
  • +1 for saying what he should do rather than why what he did gave an error (although I seem to have the tick for doing the latter, sorry:-) Oct 17, 2016 at 8:15
  • @DavidCarlisle I saw your answer with the explanations. No need to double it. And it was accepted before i decided to post. I thought about making it CW, but ...
    – Johannes_B
    Oct 17, 2016 at 8:16
  • @Johannes_B: I wish I could mark this answer as the accepted, as well. Thanks for the presented points and improvements.
    – User
    Oct 17, 2016 at 8:19

You must log in to answer this question.

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