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 »

Is there a way (surely there is!) to reduce the width of text and give more space to an answer line on the right part, in this MWE code ? (sorry for the idiotic questions in this example, but I couldn't resist and didn't found anything better in a quick rush! :oops: )

Code: Select all

\documentclass[11pt]{exam}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[margin=1in]{geometry}
\begin{document}
\begin{questions}
\question[10] Some true or false questions to answer very quick :

\medskip

\begin{parts}
	\setlength{\rightmargin}{1in}%
	\part Is it true that this sentence is false ?
	\hfill\makebox[0.5in]{\dotfill}
	\smallskip
	\part Your name is the same as what it was ten thousands of years ago. \hfill\makebox[0.5in]{\dotfill}
	\smallskip
	\part This is a long, very long, sentence that means absolutely nothing, and is here to piss you off and to bore you to death.
	\hfill\makebox[0.5in]{\dotfill}
	\smallskip
	\part This is a true-false question which doesn't have any true of false answer, just to annoy you like hell.  Geez this exam is dull !
	\hfill\makebox[0.5in]{\dotfill}
\end{parts}
\end{questions}
\end{document}
Preview :
exam.jpg
exam.jpg (34.54 KiB) Viewed 5819 times
As you can see in this very hilarious example ( :roll: ), the dotted lines aren't properly aligned, and there isn't enough space above them. How can I reduce the length of text, and get more space for the answer dotted lines ?

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

Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Reducing some text width in exam class

Post by Cham »

Now, I'm really at lost with this. Any idea how to solve the issue described above? :?:
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Reducing some text width in exam class

Post by Cham »

Using the command \newline may solve my issue, but if feels a bit hacky to me :

Code: Select all

\documentclass[11pt]{exam}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[margin=1in]{geometry}
\begin{document}
\begin{questions}
\question[10] Some true or false questions to answer very quick :

\medskip

\begin{parts}
	\setlength{\rightmargin}{1in}%
	\part Is it true that this sentence is false ?
	\hfill\makebox[0.5in]{\dotfill}
	\smallskip
	\part Your name is the same as what it was ten thousands of years ago. \hfill\makebox[0.5in]{\dotfill}
	\smallskip
	\part This is a long, very long, sentence that means absolutely nothing, and is \newline here to amuse you to death.
	\hfill\makebox[0.5in]{\dotfill}
	\smallskip
	\part This is a true-false question which doesn't have any true of false answer, \newline just to annoy you like hell.  Geez this exam is dull !
	\hfill\makebox[0.5in]{\dotfill}
\end{parts}

\end{questions}
\end{document}
And why is the last dotted line not properly aligned with the other lines ? I have to add \smallskip to fix this.
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 »

Hi Cham,

a line end is like a space. So above, you have a line end (space) and then a small skip, then a line end. In the last line there's no small skip, just a line end.

You can see it's aligned if you comment out the line end before the small skip:

Code: Select all

\documentclass[11pt]{exam}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[margin=1in]{geometry}
\begin{document}
\begin{questions}
\question[10] Some true or false questions to answer very quick :
 
\medskip
 
\begin{parts}
	\setlength{\rightmargin}{1in}%
	\part Is it true that this sentence is false ?
	\hfill\makebox[0.5in]{\dotfill}%
	\smallskip
	\part Your name is the same as what it was ten thousands of years ago. \hfill\makebox[0.5in]{\dotfill}%
	\smallskip
	\part This is a long, very long, sentence that means absolutely nothing, and is \newline here to amuse you to death.
	\hfill\makebox[0.5in]{\dotfill}%
	\smallskip
	\part This is a true-false question which doesn't have any true of false answer, \newline just to annoy you like hell.  Geez this exam is dull !
	\hfill\makebox[0.5in]{\dotfill}%
\end{parts}
 
\end{questions}
\end{document}
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 »

Is there a simple way to reduce the text width, while keeping the answer slot on the right side (after the text), without using the \newline command ?
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 »

You could use \parbox each time to limit the text width when needed.

Code: Select all

\part \parbox[t]{0.6\textwidth}{This is a true-false question
    which doesn't have any true of false answer, just to annoy you
    like hell.  Geez this exam is dull !}
    \hfill\parbox[b]{0.5in}{\dotfill}
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 »

Wow, this is great ! Thanks a lot Stefan. Case is now solved. :)
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Reducing some text width in exam class

Post by Cham »

Hmm, actually, there's a small annoying glitch : the dotted answer line is aligned with the first line of text, which isn't appropriate for this kind of questions. The answer line should be aligned with the last line of text inside the parbox. Is there a way to fix that ?
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 noticed this too. Normally I use the optional argument of \parbox for aligning (t, b or the default c). So I would choose b, but I already had to use [t] to align at the top at the left side. I could imagine setting an anchor and using a TikZ overlay for an aligned placement of the dots, but so it gets a bit complicated, perhaps you find a simpler way.

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 »

Hmm, the solution appears to be trivial : just add a space before the answer line :

Code: Select all

\documentclass[11pt]{exam}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[margin=1in]{geometry}
\begin{document}
\begin{questions}
\question[10] Some true or false questions to answer very quick :
 
\medskip
 
\begin{parts}
	\setlength{\rightmargin}{1in}%
	\part \parbox[t]{0.8\textwidth}{Is it true that this sentence is false ?}
	
	\hfill\makebox[0.5in]{\dotfill}%
	\part \parbox[t]{0.8\textwidth}{Your name is the same as what it was ten thousands of years ago.}
	
	\hfill\makebox[0.5in]{\dotfill}%
	\part \parbox[t]{0.8\textwidth}{This is a long, very long, sentence that means absolutely nothing, and is here to amuse you to death.}
	
	\hfill\makebox[0.5in]{\dotfill}%
	\part \parbox[t]{0.8\textwidth}{This is a true-false question which doesn't have any true of false answer, just to annoy you like hell.  Geez this exam is dull !}

	\hfill\makebox[0.5in]{\dotfill}%
\end{parts}
 
\end{questions}
\end{document}
What do you think?

EDIT : The vertical spacings are a bit weird, though. I'm not sure yet this solution is appropriate.
Post Reply