0

I want to create a worksheets which is similar to the first example.

enter image description here

The below code meets three problems.

  1. It can not be breakable
  2. Two examples are not top align
  3. The command create dot lines, sometimes generate error.

Please suggest me another method or correct the below codes. Thank you very much!

\documentclass[12pt]{book}
\usepackage[paperwidth=21cm,paperheight=29.7cm,top=2.5cm,bottom=2cm,left=2cm,right=1.5cm]{geometry}
\setlength{\parindent}{0.6cm}
\setlength{\parskip}{6pt}
\linespread{1.1}
\usepackage{tikz}
\usepackage{adjustbox}
\newlength\myheight
\newlength{\myheightn}
\usepackage{multido}
\newcommand{\twocols}[2]{
\par\noindent
  \begin{adjustbox}{minipage=[t]{0.5\linewidth},gstore totalheight=\myheight,margin=\fboxsep+\fboxrule} 
  \vspace*{0pt}
{\bfseries\fontfamily{qag}\selectfont Example 1}. #1    
  \end{adjustbox}
  \hspace*{\fboxsep}
  \begin{adjustbox}{minipage=[t][\myheight]{0.5\linewidth}}
 \vspace*{0pt}
  \begin{adjustbox}{minipage=[t]{0.95\linewidth},gstore totalheight=\myheightn,margin=\fboxsep+\fboxrule}
  {\bfseries\fontfamily{qag}\selectfont Example 2}. #2
  \end{adjustbox}
   \edef\sodongt{\the\numexpr\dimexpr (\myheight-\myheightn)/(\dimexpr 1.1\baselineskip\relax) \relax\relax}
   \pgfmathsetmacro{\sodong}{int(\sodongt-1)}
\par
  \noindent \makebox[0.975\linewidth]{{\bfseries\fontfamily{qag}\selectfont\color{blue}Solution}:\dotfill}
  \multido{}{\sodong}{\vspace*{2pt}\noindent\makebox[0.975\linewidth]{\dotfill}\newline}

\end{adjustbox} } \usepackage{lipsum} \begin{document} \twocols{\lipsum[12]}{a} \end{document}

2 Answers2

3

The following does with horizontal and vertical leaders.

Drawbacks:

  1. Page-breaks are not possible.

  2. As the dotted lines are drawn as vertical leaders, vertical skips in the left side other than \baselineskip are not taken into account.

\documentclass[12pt]{book}
\usepackage[paperwidth=21cm,paperheight=29.7cm,top=2.5cm,bottom=2cm,left=2cm,right=1.5cm]{geometry}
\setlength{\parindent}{0.6cm}
\setlength{\parskip}{6pt}
\linespread{1.1}
%\usepackage{tikz}
\usepackage{xcolor}
\usepackage{adjustbox}
\newlength\myheight

\makeatletter \DeclareRobustCommand\MyDotfill{% % don't use \cleaders as in \dotfill but use \leaders \leavevmode\leaders\hb@xt@ .44em{\hss.\hss}\hfill\kern\z@ }% \newcommand\Mysavedprevdepth{}% \makeatother

\newcommand{\twocols}[2]{% \par\noindent \begin{adjustbox}{minipage=[t]{\dimexpr.5\linewidth-2\fboxsep-2\fboxrule-.5\fboxsep\relax},gstore totalheight=\myheight,margin=\fboxsep+\fboxrule}% {\fontfamily{qag}\textbf{Example 1.}} #1\par\xdef\Mysavedprevdepth{\the\prevdepth}% \end{adjustbox}% \hspace*{\fboxsep}% \begin{adjustbox}{minipage=[t][\myheight]{\dimexpr.5\linewidth-2\fboxsep-2\fboxrule-.5\fboxsep\relax},margin=\fboxsep+\fboxrule}% {\fontfamily{qag}\textbf{Example 2.}} #2\par \vbox{\hbox to\hsize{\fontfamily{qag}\textbf{\color{blue}Solution:}\MyDotfill}}% \kern-\prevdepth \xleaders\vbox to\baselineskip %<-\baselineskip is the vertical distance between dotted lines. You can use any other value as well. {\vfill\hbox to\hsize{\MyDotfill}}\vfill \kern\Mysavedprevdepth \end{adjustbox}% }%

\usepackage{lipsum} \begin{document} \twocols{\lipsum[12]}{a}

\end{document}

enter image description here

Ulrich Diez
  • 28,770
  • Thank you very much. I am learning how to use vbox and hbox commands to align the paragraphs. – Nam Tran Le Jul 29 '21 at 01:16
  • From the link https://tex.stackexchange.com/questions/288574/tcolorbox-get-height-of-actual-box-from-inside-box I think we can use breakable option of tcolorbox. Please help me fill dot automatically as your code. Thank you very much – Nam Tran Le Aug 23 '21 at 11:15
0

There are many ways to do it. Here's a simple one using minipage:

\documentclass[12pt]{book}

\begin{document} \begin{minipage}[t]{\linewidth} \begin{minipage}[t]{0.4\linewidth} \textbf{Example 1.} Lorem ipsum dolor sit amet consectetuer Proin Curabitur condimentum vel Vivamus. Cursus dui vitae et facilisis Mauris sociis auctor elit interdum pede. Tristique ipsum elit ut nibh diam eget in accumsan a Lorem. Habitasse tempor dui dui dapibus justo consectetuer parturient est vitae wisi.

    \end{minipage}
    \begin{minipage}[t]{0.4\linewidth}
        \textbf{Example 2.} Here's the problem to be solved.\\

        Solution: \dotfill \\
        \hspace*{-0.5em} \dotfill \\ % use as many as you need
        \hspace*{-0.5em} \dotfill \\
        \hspace*{-0.5em} \dotfill \\
        \hspace*{-0.5em} \dotfill \\
        \hspace*{-0.5em} \dotfill \\
        \hspace*{-0.5em} \dotfill \\
        \hspace*{-0.5em} \dotfill           
    \end{minipage}
\end{minipage}

\end{document}

Result:

Result using minipage

MS-SPO
  • 11,519
  • Thank you. I want to do it automatically. – Nam Tran Le Jul 27 '21 at 09:09
  • 1
    See e.g. here for multiple dotted lines: https://tex.stackexchange.com/questions/248451/how-to-create-multiple-dotted-lines . You may want to use package calc, like here: https://tex.stackexchange.com/questions/18576/get-width-of-a-given-text-as-length , to determine the required number of lines. Try also defining your text as macros for this purpose, like \TL here for your TextLeft: \def\TL{\textbf{Example 1.} Lorem ipsum dolor sit amet consectetuer Proin Curabitur condimentum vel Vivamus. Cursus dui vitae et facilisis } – MS-SPO Jul 27 '21 at 12:57
  • 1
    Thank you very much! – Nam Tran Le Jul 27 '21 at 13:27
  • Fine. Should you find a solution, please don't hesitate to post it as an (i.e. your) answer here ;-) – MS-SPO Jul 27 '21 at 16:45
  • 1
    It is almost successful sir. – Nam Tran Le Jul 28 '21 at 03:25