I'm using the article document class. How do you make an answer box that is in line with the text like in the picture?
2 Answers
I use TikZ to create a node for the item's text and to draw a rectangle aside. The solution is mainly based on the use of (current bounding box).
Remark. The alignment of the node with respect to the text is based on @Marco Daniel 's answer at How to make a tikz node, top-aligned with the rest of the text?.
The code
\documentclass[11pt, a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}
\begin{document}
\newcommand{\ibox}[1]{%
\begin{tikzpicture}[baseline={%
([yshift={-\ht\strutbox +.2ex}]current bounding box.north)
},
outer sep=0pt, inner sep=0pt]
\path (0, 0)
node[anchor=north west,
inner sep=0, outer sep=0,
text width=\linewidth] (tmp)
{#1};
\draw (\linewidth +3ex, 0) rectangle
($(current bounding box.south east) +(\marginparwidth+5ex, 0)$);
\end{tikzpicture}
}
\section{Verification}
\begin{enumerate}
\item \ibox{\lipsum[1]}
\item \ibox{\lipsum[2]}
\end{enumerate}
\end{document}
- 5,687
Another approach is using a table, I am using tabularray here:
\documentclass[12pt]{article}
\usepackage{tabularray}
\usepackage{tikz}
\UseTblrLibrary{booktabs,counter,varwidth}
\newcounter{mycnta}
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}
\usepackage[a4paper, total={180mm,257mm},left=15mm,top=20mm]{geometry}
\usepackage{caption}
\usepackage{blindtext}
\begin{document}
\textbf{BAGIAN PERTAMA}
\vspace{3mm}
\begin{tblr}{colspec={Q[.5cm,c]X[j]Q[c,3cm]},rows={m},cell{1-5}{1}={r=1,c=1}{h}}
\mycnta. & Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobor-
tis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent
imperdiet mi nec ante. Donec ullamcorper, felis non sodales commodo,
lectus velit ultrices augue, a dignissim nibh lectus placerat pede. Vivamus
nunc nunc, molestie ut, ultricies vel, semper in, velit. Ut porttitor. Prae-
sent in sapien. & \tikz[baseline=(current bounding box.center)] \draw (0,0) rectangle (2.5,1.5); \\
& & \\
\mycnta. & Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobor-
tis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent
imperdiet mi nec ante. Donec ullamcorper, felis non sodales commodo,
lectus velit ultrices augue, a dignissim nibh lectus placerat pede. Vivamus
nunc nunc, molestie ut, ultricies vel, semper in, velit. Ut porttitor. Prae-
sent in sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Duis fringilla tristique neque. Sed interdum libero ut metus. & \tikz[baseline=(current bounding box.center)] \draw (0,0) rectangle (2.5,1.5); \\
& & \\
\mycnta. & \blindtext & \tikz[baseline=(current bounding box.center)] \draw (0,0) rectangle (2.5,1.5); \\
\end{tblr}
\end{document}
- 2,605
-
1I've been thinking about the idea of using a table for a while and haven't figured out how to position the box right in the middle of the beginning and end of a sentence. Thanks and this has solved my problem above. – Wildan Bagus W Jan 02 '23 at 13:14



enumerateenvironment items. Is this so? – Daniel N Jan 01 '23 at 12:29