
나는 여러 개의 섹션을 생성하고 각 섹션 뒤에 여러 줄을 추가하고 싶습니다. i. 이것은 사용자 정의 명령 \drawline을 i번 반복하기 위해 multido를 사용하여 수행한 방법입니다.
\documentclass[12pt]{memoir}
\usepackage{tikz}
\usepackage{multido}
\newcommand{\drawline}{%
\begin{tikzpicture}%
\draw [gray] (0,0) -- (\textwidth, 0);%
\node [above right] at (0,0) {\i.};
\end{tikzpicture}%
\\%
}
\begin{document}
\section*{Section 1}
\multido{\i=1+1}{5}{\drawline}
\section*{Section 2}
\multido{\i=1+1}{4}{\drawline}
\end{document}
이는 다음을 생성합니다.
\\
내가 겪고 있는 문제는 tikzpicture 정의 다음에 나오는 브레이크라인과 관련된 것 같습니다 . \drawline 호출 사이에 줄을 끊어서 줄이 나란히 표시되지 않고 순서대로 표시되도록 해야 합니다. 그러나 두 가지 문제가 있습니다.
- \drawline을 마지막으로 호출한 후에 불필요한 빈 줄이 추가로 생겼는데, 이는 섹션 사이에 추가 공간이 있음을 의미합니다.
- 한 섹션의 줄이 페이지를 어느 정도 완벽하게 채우면 다음 섹션이 다음 페이지에 나타나지만 페이지 상단에는 나타나지 않습니다. 페이지 상단과 섹션 제목 사이에 공백이 있습니다.
문서에 따르면 multido의 구문은 다음과 같습니다.
\multido{*variables*}{*repetitions*}{*stuff*}
참고할 수 있는 방법이 있나요반복변수로? 예를 들어, n <인 경우 모든 n에 줄 바꿈을 적용하려는 경우반복? 이 경우 조건문을 사용하여 마지막 경우를 제외한 모든 경우에 줄바꿈을 할 수 있습니다.
아니면 다른 tikzpicture를 기준으로 tikzpicture의 좌표를 대신 사용할 수 있습니까? 이런 식으로 \drawline은 \\
끝에 의존하지 않고 정의될 수 있습니다 .
답변1
로드된 multido
경우에는 사용할 필요가 없습니다 . tikz
그냥 사용하십시오 \foreach
:
\documentclass[12pt]{memoir}
\usepackage{tikz}
\newcommand{\linespace}{6mm}
\newcommand{\drawlines}[1]{\tikz{\foreach \n in {1,...,#1}
{\draw[gray](0,-\n*\linespace)node[above right,black]{\n.}--(\textwidth,-\n*\linespace);}}}
\begin{document}
\section*{Section 1}
\drawlines{5}
\section*{Section 2}
\drawlines{4}
\end{document}
답변2
해당 색인도 사용하여 주어진 횟수만큼 반복하는 상당히 일반적인 방법입니다.
\documentclass[12pt]{memoir}
\ExplSyntaxOn
\NewDocumentCommand{\REPEAT}{mm}
{% #1 = number of lines to print, #2 = what to repeat
\int_step_inline:nn { #1 } { #2 }
}
\ExplSyntaxOff
\newcommand{\drawline}[1]{%
\noindent\makebox[0pt][l]{#1.}%
\leaders\hrule height -2pt depth 2.2pt \hfill
\hspace*{0pt}\par
}
\newcommand{\drawlines}[1]{\REPEAT{#1}{\drawline{##1}}}
\begin{document}
\section{Title}
\drawlines{5}
\section{Title}
\drawlines{4}
\end{document}
첫 번째 인수는 \REPEAT
반복 횟수입니다. 두 번째 인수는 실행할 코드이며, 여기서 인덱스를 참조할 수 있습니다 ##1
.
특별한 경우에는 오른쪽으로 튀어나온 너비가 0인 상자에 현재 인덱스를 설정한 다음 기준선 아래 2pt, 두께 0.2pt로 전체 텍스트 너비의 규칙을 그리는 매크로를 \REPEAT
원합니다 .\drawline
답변3
Ti를 사용할 필요는 없습니다.케이Z를 사용하려면 LaTeX에 내장된 다음을 사용할 수도 있습니다 \rule
.
\documentclass[12pt]{memoir}
\usepackage{xcolor}
\makeatletter
\newcommand\drawline[1]
{\expandafter\drawline@\expandafter1\expandafter;\the\numexpr#1;}
\def\drawline@#1;#2;%
{%
\ifnum#1>#2
\expandafter\@gobbletwo
\fi
\@firstofone
{%
\drawline@output{#1}%
\expandafter\drawline@\the\numexpr#1+1;#2;%
}%
}
\newcommand\drawline@output[1]
{%
\par
\noindent\rlap{#1.}%
\textcolor{gray}{\rule[-0.3333em]{\linewidth}{.4pt}}%
\par
}
\makeatother
\begin{document}
\section*{Section 1}
\drawline{5}
\section*{Section 2}
\drawline{4}
\end{document}
답변4
\rule
(Skillmon의 답변을 기반으로)를 사용하는 LaTeX3 버전
\documentclass{article}
\usepackage{xcolor}
\ExplSyntaxOn
\int_new:N \g_dl_line_count
\NewDocumentCommand{\drawlines}{ m }{
\int_set:Nn \g_dl_line_count {1}
\prg_replicate:nn {#1} {%
\par
\noindent\rlap{\int_use:N \g_dl_line_count.}%
\textcolor{gray}{\rule[-0.3333em]{\linewidth}{.4pt}}%
\par
\int_incr:N \g_dl_line_count
}
}
\ExplSyntaxOff
\begin{document}
\section*{Section 1}
\drawlines{5}
\section*{Section 2}
\drawlines{4}
\end{document}