Fonts & Character SetsMultiple Options in single Line

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
Post Reply
sachinrajsharma
Posts: 35
Joined: Sun Apr 08, 2012 5:48 am

Multiple Options in single Line

Post by sachinrajsharma »

Hi,
Good Day!

I am writing few multiple choice questions but in the below code it is coming in column, which is consuming more space.

Code: Select all

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}

\begin{document}
  \begin{enumerate}
    \item $\int_0^1 e^{2lnx}dx = $
    \begin{enumerate}
      \item 0
      \item $\frac{1}{2}$
      \item $\frac{1}{3}$
      \item $\frac{1}{4}$
    \end{enumerate}
    \item $\int^{\frac{\pi}{4}}_0 tan^2xdx$ = 
    \begin{enumerate}
      \item $1-\frac{\pi}{4}$
      \item $1 +\frac{\pi}{4}$
      \item $\frac{\pi}{4}-1$
      \item $\frac{\pi}{4}$
    \end{enumerate}
  \end{enumerate}
\end{document}
So, I want to write the four options of question in single row. Please help how to do this.


Thanks.
Sachin

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

tom
Posts: 73
Joined: Thu Apr 18, 2013 4:02 am

Multiple Options in single Line

Post by tom »

Hello!

For in-line enumeration, use the paralist package. See here for an example.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Multiple Options in single Line

Post by localghost »

For this purpose it is better to use a class like exam or a package like exsheets.

Here is an example with exam

Code: Select all

\documentclass[11pt,a4paper]{exam}
\usepackage[T1]{fontenc}
\usepackage{mathtools}

\everymath={\displaystyle}
\renewcommand*{\thechoice}{\alph{choice}}
\renewcommand*{\choicelabel}{(\thechoice)}
%\renewcommand*{\choicelabel}{%  % workaround for more space between choices
%  \ifnum\value{choice}>1%
%    \makebox[5em][r]{(\thechoice)}%
%  \else
%    (\thechoice)
%  \fi%
%}

\begin{document}
  \begin{questions}
    \question $\int_0^1 e^{2lnx}\,dx=$

    \begin{oneparchoices}
      \choice 0
      \choice $\frac{1}{2}$
      \choice $\frac{1}{3}$
      \choice $\frac{1}{4}$
    \end{oneparchoices}

    \question $\int^{\frac{\pi}{4}}_0 tan^2x\,dx$ = 

    \begin{oneparchoices}
      \choice $1-\frac{\pi}{4}$
      \choice $1 +\frac{\pi}{4}$
      \choice $\frac{\pi}{4}-1$
      \choice $\frac{\pi}{4}$
    \end{oneparchoices}
  \end{questions}
\end{document}
… and another one with exsheets.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage[load-tasks=true]{exsheets}

\SetupExSheets{headings=runin}
\everymath={\displaystyle}

\begin{document}
  \begin{question}
    $\int_0^1 e^{2lnx}\,dx = $
  \end{question}
  \begin{tasks}[label=(tsk[a]),label-width=2em](4)
    \task 0
    \task $\frac{1}{2}$
    \task $\frac{1}{3}$
    \task $\frac{1}{4}$
  \end{tasks}

  \begin{question}
    $\int^{\frac{\pi}{4}}_0 tan^2x\,dx$ = 
  \end{question}
  \begin{tasks}[label=(tsk[a]),label-width=2em](4)
    \task $1-\frac{\pi}{4}$
    \task $1 +\frac{\pi}{4}$
    \task $\frac{\pi}{4}-1$
    \task $\frac{\pi}{4}$
  \end{tasks}
\end{document}
If you want to stay with the classic list environments, try enumitem in this way.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[inline]{enumitem}
\usepackage{mathtools}

\everymath={\displaystyle}
\setlist[enumerate,2]{label=(\alph*)}

\begin{document}
  \begin{enumerate}
    \item $\int_0^1 e^{2lnx}\,dx=$

    \begin{enumerate*}[itemjoin=\qquad]
      \item 0
      \item $\frac{1}{2}$
      \item $\frac{1}{3}$
      \item $\frac{1}{4}$
    \end{enumerate*}
    \item $\int^{\frac{\pi}{4}}_0 tan^2x\,dx=$
    
    \begin{enumerate*}[itemjoin=\qquad]
      \item $1-\frac{\pi}{4}$
      \item $1 +\frac{\pi}{4}$
      \item $\frac{\pi}{4}-1$
      \item $\frac{\pi}{4}$
    \end{enumerate*}
  \end{enumerate}
\end{document}
For a deeper understanding of the involved packages take a look at their manuals.


Thorsten
Post Reply