使答案框与文本内嵌

使答案框与文本内嵌

我用的是article文档类,如何制作像图片中那样与文本对齐的答案框?

在此处输入图片描述

答案1

另一种方法是使用表格,我tabularray在这里使用:

\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

在此处输入图片描述

我使用TikZ为项目的文本创建一个节点,并在旁边绘制一个矩形。解决方案主要基于 的使用(current bounding box)

评论。 节点相对于文本的对齐基于@Marco Daniel 的回答 如何制作一个 tikz 节点,与文本的其余部分顶部对齐?

代码

\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}

相关内容