我正在尝试创建一个书法模板。我希望它看起来像下面这张图片,但没有边距和标题(A4 纸)。我想要三种类型的线条:
- 水平线每隔 1 厘米交替一次,深黑色。
- 水平线每 0.5 厘米交替出现,颜色为浅灰色。它们基本上位于 1 厘米黑色线条之间。
每 1 厘米交替呈 55 度角的线条,红色。如果该角度是一个变量,那么我以后可以根据需要进行更改,这样就更好了。
这是我目前能做到的,但由于我是基于直角坐标系绘制线条,所以我不知道如何将斜线的角度调整为 55 度。我基本上只需要修复这一点;除此之外,我对结果很满意。
\documentclass[letterpaper]{article} %为了呈现图片,不包括“草稿” \usepackage{tikz} \usetikzlibrary{计算} \usepackage{逐字} \开始{文档} \pagestyle{空} \begin{tikzpicture}[记住图片,覆盖] \foreach \i 在 {1,2,3,...,30}{ \draw[black] ($(当前页面.西北)+(0,-\i)$) -- ($(当前页面.东北)+(0,-\i)$);} \foreach \i 在 {0.5,1.5,2.5,...,60}{ \draw[lightgray] ($(当前页面.西北)+(0,-\i)$) -- ($(当前页面.东北)+(0,-\i)$);} \foreach \i 在 {1,2,3,...,60}{ \draw[red] ($(当前页面.西南)+(0,-\i)$) -- ($(当前页面.东北)+(0,-\i)$);} \foreach \i 在 {0,1,2,3,...,60}{ \draw[red] ($(当前页面.西南)+(0,+\i)$) -- ($(当前页面.东北)+(0,+\i)$);} \结束{tikzpicture} \结束{文档}
这是我的输出。
答案1
您可以使用极坐标,例如(55:100cm)
。在下面的代码中,我根据所选角度和两条连续斜线之间的\myAngle
距离计算要绘制的斜线的精确数量。我的代码还计算了这些线所需的最大长度。\myDist
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\newcommand*{\myDist}{1cm} % distance between consecutive oblique lines
\newcommand*{\myAngle}{55} % angle of said lines wrt horizontal, in degrees
% Distance between consecutive oblique lines, projected on the horizontal axis
\pgfmathsetlengthmacro{\horizIntervWidth}{\myDist/sin(\myAngle)}
% Length of the longest oblique lines we'll need. I add 10pt to be 100% safe
% with respect to rounding errors (the lines will be clipped anyway).
\pgfmathsetlengthmacro{\maxLength}{10pt + \paperheight/sin(\myAngle)}
% Number of oblique lines to draw
\pgfmathtruncatemacro{\maxIndex}{
round((\paperheight/tan(\myAngle) + \paperwidth)/\horizIntervWidth)}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
% Just to be sure we don't paint outside the page. :-)
\clip (current page.south west) rectangle (current page.north east);
\foreach \i in {1,2,...,30} {
\draw[black] ($(current page.north west)+(0,-\i)$) --
($(current page.north east)+(0,-\i)$);
}
\foreach \i in {0.5,1.5,...,60} {
\draw[lightgray] ($(current page.north west)+(0,-\i)$) --
($(current page.north east)+(0,-\i)$);
}
\foreach \i in {1,2,...,\maxIndex} {
\draw[red] ([xshift=-\i*\horizIntervWidth]current page.south east) --
+(\myAngle:\maxLength);
}
\end{tikzpicture}
\end{document}
答案2
这确实不是回答您的具体问题,但可以适应您的使用,并内置了许多其他选项。我试图根据您的要求设置默认值(留在垂直线中,但您可以通过将其放在和draw=none
的末尾来禁用它。Vertical Line Style
Vertical Line Style Alternate
笔记:
- 有三种不同类型的线:水平线、垂直线和水平倾斜线。
- 倾斜角度可以通过 设置
\SlantAngle
。 - 每种线条样式都有
\tikzset
一种替代样式应用于每第 n 条线,并且每种线条样式都有两种与之关联的线条样式:主样式和替代线条样式。 - 边框是可选的,可以通过设置、
\MarginTop
和\MarginBottom
来禁用。\MarginLeft
\MarginRight
0.0cm
代码:
%% Calligraphy Guide Lines
%% Peter Grill
%%
%% ---------------------- Note: May need to run this twice ---------------------
%%
%% --------------------------------------------------- Select Lines
%% ---------------------------------------------------------------- Horizontal Lines
\def\VerticalSkip{1.0cm}% 0.10cm through 2cm
\def\UseAltStyleEveryNthHorizontalLine{2}%
%% ---------------------------------------------------------------- Vertical Slant Lines
\def\HorizontalSlantSkip{1.0cm}%
\def\SlantAngle{55}% Degrees >30, < 60
\def\UseAltStyleEveryNthSlantLine{4}%
%% ---------------------------------------------------------------- Vertical Lines
\def\HorizontalSkip{2.66625cm}%
\def\UseAltStyleEveryNthVerticalLine{5}%
%% ---------------------------------------------------------------- Select Margins
\def\MarginTop{0.25cm}
\def\MarginBottom{0.25cm}
\def\MarginLeft{0.25cm}
\def\MarginRight{0.25cm}
%% ---------------------------------------------------------------- Select Paper
\def\Paper{a4paper}% letter | a4paper | a5paper, ....
\def\Orientation{portrait}%% portrait | landscape
%% -----------------------
\documentclass[\Paper, \Orientation]{article}% Version 1.1
\usepackage{tikz}
\usepackage{xstring}
\pagestyle{empty}
%% Select the line style. I prefer using the second one here and using the output underneath
%% the actual paper as guide lines. The first is better if you want to actually write on
%% top of the guide lines
%%
%% Few other options that can be applied here (last applied options override earlier ones).
%% solid
%% dotted, densely dotted, loosely dotted,
%% dashed, densely dashed, loosely dashed,
%% dash dot dot, densely dash dot dot, loosely dash dot dot,
%% loosely dashed,
%%
%% Custom line styles can be defined also be specifying the on/off patter:
%% dash pattern=on 2pt off 3pt on 4pt off 4pt
%%
%% To disable ANY lines use the draw=none as the last style.
%\tikzset{Line Style/.style={line width=1pt, densely dotted, gray, draw opacity=0.1}}
\tikzset{Line Style/.style={
line width=0.2pt,
solid,
gray,
draw opacity=0.5
}}
\tikzset{Horizontal Line Style/.style={
Line Style,
solid,
}}
\tikzset{Horizontal Line Style Alternate/.style={
Line Style,
line width=0.2pt,
dashed,
draw opacity=1.0,
}}
\tikzset{Slant Line Style/.style={
Line Style
}}
\tikzset{Slant Line Style Alternate/.style={
Line Style,
line width=0.2pt,
solid,
draw opacity=1.0,
red
}}
\tikzset{Vertical Line Style/.style={Line Style, line width=0.1pt}}
\tikzset{Vertical Line Style Alternate/.style={Line Style, line width=0.1pt}}
\tikzset{Border Line Style/.style={Line Style, thin}}
\newlength{\DeltaY}
\newlength{\TempLength}
\pgfmathtruncatemacro{\MaxHorizontalLines}{\paperheight/\VerticalSkip}
\pgfmathsetmacro{\TanSlantAngle}{tan(\SlantAngle)}
\pgfmathsetlength{\DeltaY}{\HorizontalSlantSkip*\TanSlantAngle}
\pgfmathtruncatemacro{\MaxSlantLinesX}{\paperwidth/\HorizontalSlantSkip}
\pgfmathtruncatemacro{\MaxSlantLinesY}{\paperheight/\DeltaY}
\pgfmathtruncatemacro{\MaxVerticalLines}{\paperwidth/\HorizontalSkip}
\newcommand*{\SetLineStyle}[4]{%
%% #1 = style name to set
%% #2 = default line style
%% #3 = line number
%% #4 = which lines get the alternate line style
\pgfmathtruncatemacro{\Remainder}{mod(#3,#4)}%
\ifnum\Remainder=0\relax
\tikzset{#1/.style={#2 Alternate}}%
\else
\tikzset{#1/.style={#2}}%
\fi
}%
\begin{document}%
\begin{tikzpicture}[
remember picture,
overlay,
shift=(current page.south west),% So that (0,0) is south west of paper
]
%% Clip to create the border
\clip (\MarginLeft,\MarginBottom) rectangle
(\paperwidth-\MarginRight,\paperheight-\MarginTop);
\foreach \y in {1,...,\MaxHorizontalLines} {% Horizontal guide lines
\SetLineStyle
{This Horizontal Line Style}{Horizontal Line Style}
{\y}{\UseAltStyleEveryNthHorizontalLine}
\begin{scope}[yshift=-\MarginTop]
\draw[This Horizontal Line Style]
(0pt,\paperheight-\y*\VerticalSkip) -- (\paperwidth,\paperheight-\y*\VerticalSkip)
;
\end{scope}
}
\foreach \x in {1,...,\MaxVerticalLines} {% Vertical guide lines
\SetLineStyle
{This Vertical Line Style}{Vertical Line Style}
{\x}{\UseAltStyleEveryNthVerticalLine}
\begin{scope}[xshift=\MarginLeft]
\draw[This Vertical Line Style]
(\x*\HorizontalSkip,0pt) -- (\x*\HorizontalSkip,\paperheight)
;
\end{scope}
}
\pgfmathsetlength{\TempLength}{\paperwidth*\TanSlantAngle}
\foreach \x in {0,...,\MaxSlantLinesX} {% Slant Lines starting along bottom of page
\SetLineStyle
{This Slant Line Style}{Slant Line Style}
{\x}{\UseAltStyleEveryNthSlantLine}
\draw[This Slant Line Style]
(\x*\HorizontalSlantSkip,0pt) -- ++(\paperwidth,\TempLength)
;
}
\foreach \y in {1,...,\MaxSlantLinesY} {% Slant Lines starting along left of page
\SetLineStyle
{This Slant Line Style}{Slant Line Style}
{\y}{\UseAltStyleEveryNthSlantLine}
\draw[This Slant Line Style]
(0pt,\y*\DeltaY) -- ++(\paperwidth,\TempLength)
;
}
%% Draw border
\draw [Border Line Style]
(\MarginLeft,\MarginBottom) rectangle
(\paperwidth-\MarginRight,\paperheight-\MarginTop);
\end{tikzpicture}%
\end{document}
答案3
另一种无需 的解决方案calc
。
\documentclass[a4paper]{article} %do not include "draft" in order to render pictures
\usepackage{tikz}
%\usetikzlibrary{calc}
\usepackage{verbatim}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[remember picture,overlay]
\foreach \i in {1,2,3,...,30}{
\draw[black] ([yshift=-\i cm]current page.north west) -- ++(0:\paperwidth);}
\foreach \i in {0.5,1.5,2.5,...,60}{
\draw[lightgray] ([yshift=-\i cm]current page.north west) -- ++(0:\paperwidth);}
\foreach \i in {1,2,3,...,60}{
\draw[red] ([xshift=\i cm]current page.north west) -- ++(235:2*\paperheight);}
\end{tikzpicture}
\end{document}
答案4
以下是元帖子包裹在 中luamplib
。你可以用 来编译它lualatex
。
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
beginfig(1);
numeric r, u, v;
r = 55; % angle of lines (to horizontal)
u = 1cm; % horizontal spacing
v = 5mm; % vertical spacing
color base, mid, slant;
base = 1/4 white;
mid = 3/4 white;
slant = 3/4[red, white];
drawoptions(withpen pencircle scaled 1/4);
for x = -60 upto 60:
draw (left--right) scaled 80cm rotated r shifted (x * u, 0) withcolor slant;
endfor
for y = -30 upto 30:
draw (left--right) scaled 20cm shifted (0, y * 5mm) withcolor if odd y: mid else: base fi;
endfor
clip currentpicture to unitsquare shifted -(1/2, 1/2) xscaled 200mm yscaled 280mm;
endfig;
\end{mplibcode}
\end{document}
这将生成如下页面: