# Auto-generated dot lines

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

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}
\usepackage{tikz}
\newlength\myheight
\newlength{\myheightn}
\usepackage{multido}
\newcommand{\twocols}[2]{
\par\noindent
\vspace*{0pt}
{\bfseries\fontfamily{qag}\selectfont Example 1}. #1
\hspace*{\fboxsep}
\vspace*{0pt}
{\bfseries\fontfamily{qag}\selectfont Example 2}. #2
\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}
}
\usepackage{lipsum}
\begin{document}
\twocols{\lipsum[12]}{a}
\end{document}


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}
%\usepackage{tikz}
\usepackage{xcolor}
\newlength\myheight

\makeatletter
\DeclareRobustCommand\MyDotfill{%
}%
\newcommand\Mysavedprevdepth{}%
\makeatother

\newcommand{\twocols}[2]{%
\par\noindent
{\fontfamily{qag}\textbf{Example 1.}} #1\par\xdef\Mysavedprevdepth{\the\prevdepth}%
\hspace*{\fboxsep}%
{\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
}%

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

\end{document}


• Thank you very much. I am learning how to use vbox and hbox commands to align the paragraphs. Jul 29 at 1:16
• From the link tex.stackexchange.com/questions/288574/… I think we can use breakable option of tcolorbox. Please help me fill dot automatically as your code. Thank you very much Aug 23 at 11:15

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:

• Thank you. I want to do it automatically. Jul 27 at 9:09
• See e.g. here for multiple dotted lines: tex.stackexchange.com/questions/248451/… . You may want to use package calc, like here: tex.stackexchange.com/questions/18576/… , 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 } Jul 27 at 12:57
• Thank you very much! Jul 27 at 13:27
• Fine. Should you find a solution, please don't hesitate to post it as an (i.e. your) answer here ;-) Jul 27 at 16:45
• It is almost successful sir. Jul 28 at 3:25