3

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?

enter image description here

  • From the attached image, one can think the you want the boxes only on the right of enumerate environment items. Is this so? – Daniel N Jan 01 '23 at 12:29
  • That's right. Then, the box is located in the middle of the first line and the last line of the text. – Wildan Bagus W Jan 01 '23 at 12:35
  • What will be the purpose of that box? You need to have some kind of access to it, I suppose. – Daniel N Jan 02 '23 at 07:34
  • The box is a place to write answers to questions on the side. The desired answer is only a short answer (the final result is like a number). – Wildan Bagus W Jan 02 '23 at 13:13

2 Answers2

4

enter image description here

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}

Daniel N
  • 5,687
3

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}

enter image description here

miltos
  • 2,605
  • 1
    I'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