Text FormattingReducing some text width in exam class

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Reducing some text width in exam class

Post by Cham »

Stefan, I need some opinion on this solution. Adding \vspace{-1ex} gives some nice output, but I'm not even sure to understand what I'm doing here! :oops:

Code: Select all

\documentclass[11pt]{exam}
\begin{document}
\begin{questions}
\question[10] Some true or false questions to answer very quickly, without thinking :
 
\medskip
 
\begin{parts}
	\part \parbox[t]{0.8\textwidth}{Is it true that this sentence is false ?}

	\vspace{-1ex}\hfill\makebox[0.5in]{\dotfill}%
	\smallskip
	\part \parbox[t]{0.8\textwidth}{Your name is the same as what it was ten thousands of years ago.}

	\vspace{-1ex}\hfill\makebox[0.5in]{\dotfill}%
	\smallskip
	\part \parbox[t]{0.8\textwidth}{This is a long, very long and boring sentence that means absolutely nothing, and is here to amuse you.}

	\vspace{-1ex}\hfill\makebox[0.5in]{\dotfill}%
	\smallskip
	\part \parbox[t]{0.8\textwidth}{This is a true-false question which doesn't have any true or false answer, just to annoy you like hell.  Failing this kind of exam is fun!}
	
	\vspace{-1ex}\hfill\makebox[0.5in]{\dotfill}%
\end{parts}
 
\end{questions}
\end{document}

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

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Reducing some text width in exam class

Post by Stefan Kottwitz »

Here's a way: it puts a parbox with the needed height, and the dots in the last line:

Code: Select all

\documentclass[11pt]{exam}
\begin{document}
\begin{questions}
\question[10] Some true or false questions to answer very quickly, without thinking :
 
\medskip

\newcommand{\linedots}[2][1]{%
  \hfill\parbox[t][#1\baselineskip][t]{0.5in}{#2\mbox{}\dotfill}}
\newcommand{\onelinedots}{\linedots{}}
\newcommand{\twolinedots}{\linedots[2]{\mbox{}\\}}
\newcommand{\threelinedots}{\linedots[3]{\mbox{}\\\mbox{}\\}}
  
\begin{parts}
	\part \parbox[t]{0.8\textwidth}{Is it true that this sentence is false ?}
	\onelinedots

	\part \parbox[t]{0.8\textwidth}{This is a long, very long and boring sentence that means absolutely nothing, and is here to amuse you.}
	\twolinedots

	\part \parbox[t]{0.8\textwidth}{This is a true-false question which doesn't have any true or false answer, just to annoy you like hell.  Failing this kind of exam is fun! Believe it or not - this is for filling three lines, the third one nearly up to the end.}
	\threelinedots%
\end{parts}
 
\end{questions}
\end{document}
Stefam
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Reducing some text width in exam class

Post by Cham »

That's a bit complicated for my taste. How to achieve a similar result, manually (without using a macro)?

Or how to change the \vspace{-1ex} that I used above, so the answer line is well aligned with the last line of text?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Reducing some text width in exam class

Post by Stefan Kottwitz »

I used the macro to simplify things in the document itself. In the text, it looks pretty clear.

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Reducing some text width in exam class

Post by Cham »

Well, I would like to know how to do the same manually, without the macros. It's not clear to me how the macro is working. And in some cases, I may even have some longer text (that would be very rare, though).

Or in other words : how can I change my use of \vspace{-1ex} so the answer line is properly aligned with the last line of text?
Post Reply