tikz绘制表格最后一行对不齐

2019-12-18 11:44发布

```tex \documentclass[8pt]{extarticle} \usepackage[UTF8]{ctex} \usepackage[paperwidth=21cm,paperheig...

```tex \documentclass[8pt]{extarticle} \usepackage[UTF8]{ctex} \usepackage[paperwidth=21cm,paperheight=29.7cm,top=2.4cm,bottom=2.4cm,right=0.78cm,left=1.78cm]{geometry} \usepackage{fancyhdr} \usepackage{tikz} \setlength{\linewidth}{18.44cm} \makeatletter \newlength{\blk@height} \newlength{\blk@width} \newlength{\blk@cell@ht} \newlength{\blk@cell@dp} \newlength{\blk@cell@total} \newlength{\blk@cell@wd} \setlength{\blk@height}{\dimexpr\pagegoal-\pagetotal\relax} \setlength{\blk@width}{\linewidth} \setlength{\blk@cell@ht}{26pt} \setlength{\blk@cell@dp}{4pt} \setlength{\blk@cell@total}{\dimexpr\blk@cell@ht + \blk@cell@dp\relax} \setlength{\blk@cell@wd}{26pt} %\pgfmathsetmacro{\rowCount}{floor(\blk@height / \blk@cell@total) - 1} \newcommand{\drawBlocks}[1]{% \def\rowCount{#1}% \pgfmathsetmacro{\colCount}{floor(\blk@width / \blk@cell@wd)}% \vspace{\dimexpr\blk@cell@dp-\lineskip\relax} \foreach \y in {0, ..., \rowCount} { \begin{tikzpicture} \draw (0, \y * -\blk@cell@total) -- +(\blk@cell@wd * \colCount, 0) ++(0, -\blk@cell@ht) -- +(\blk@cell@wd * \colCount, 0); \foreach \x in {0, ..., \colCount} { \draw (\x * \blk@cell@wd, \y * -\blk@cell@total) -- +(0pt, -\blk@cell@ht); } \end{tikzpicture} \vspace{\dimexpr\blk@cell@dp-\lineskip\relax} }% } \makeatother \pagestyle{fancy} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt} \begin{document} \noindent 12.写作表达\quad\\[0pt]从下面两题中任选一题,按要求完成任务。\quad\\[0pt]\indent \textbf{题一:开在心中的花朵}\quad\\[0pt]\indent \textbf{题二:我最想感谢的人}\quad\\[0pt]\indent 要求:\textcircled{1}不少于600字;\textcircled{2}书写工整,语句通顺,勿写错别字;\textcircled{3}有事例,有真情实感。\quad\\[0pt] \quad\\[0pt] \drawBlocks{40} %\colCount \end{document} ``` ![](https://pics.latexstudio.net/data/images/201912/f5b45fc24cf1cef.png)
2条回答
咸菜的味道
2019-12-18 16:22
把你的代码修改了。 ```tex \documentclass[8pt]{extarticle} \usepackage[UTF8]{ctex} \usepackage[paperwidth=21cm,paperheight=29.7cm,top=2.4cm,bottom=2.4cm,right=0.78cm,left=1.78cm]{geometry} \usepackage{fancyhdr} \usepackage{tikz} \setlength{\linewidth}{18.44cm} \makeatletter \newlength{\blk@height} \newlength{\blk@width} \newlength{\blk@cell@ht} \newlength{\blk@cell@wd} \setlength{\blk@height}{\dimexpr\pagegoal-\pagetotal\relax} \setlength{\blk@width}{\linewidth} \setlength{\blk@cell@ht}{26pt} \setlength{\blk@cell@wd}{26pt} \newcommand{\drawBlocks}[1]{% \def\rowCount{#1}% \pgfmathsetmacro{\colCount}{floor(\blk@width / \blk@cell@wd)}% \foreach \n in {1, ..., \rowCount} {% \ifnum\n=\rowCount% \def\aaaa{\relax}% \else% \def\aaaa{\\[4pt]}% \fi% \begin{tikzpicture}[line width=0.8pt] \draw (0, 0) -- ++(\blk@cell@wd * \colCount, 0) --++(0, \blk@cell@ht) -- ++(-\blk@cell@wd * \colCount, 0) -- cycle; \foreach \x in {0, ..., \colCount} { \draw (\x * \blk@cell@wd, 0) -- +(0pt, \blk@cell@ht); } \end{tikzpicture}\aaaa }% } \makeatother \pagestyle{fancy} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt} \begin{document} \noindent 12.写作表达\quad\\[0pt]从下面两题中任选一题,按要求完成任务。\quad\\[0pt]\indent \textbf{题一:开在心中的花朵}\quad\\[0pt]\indent \textbf{题二:我最想感谢的人}\quad\\[0pt]\indent 要求:\textcircled{1}不少于600字;\textcircled{2}书写工整,语句通顺,勿写错别字;\textcircled{3}有事例,有真情实感。 \vspace{3mm} \noindent \drawBlocks{40} \end{document} ``` 我编译后没问题。

一周热门 更多>