我正在尝试完成这幅画:
我的文本没有分成两行,黑线超出了红圈。你能帮我解决这个问题吗?
这是我目前拥有的代码:
\documentclass[border=5pt, multi, tikz]{standalone}
\usetikzlibrary{arrows.meta,decorations.markings}
\usepackage{amsmath}
\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}
\draw[very thick](0,0) -- (7,0) node [right] {Light to the East // of mast means 11};
\draw[black!80,fill=white] (1,0) circle (.2cm) node [left] {Light to the West // of mast means 00};
\draw[black!80,fill=red] (3.5,-3) circle (.2cm);
\draw[black!80,fill=red] (3.5,3) circle (.2cm) node [above] {Light to the North // of mast means 01};
\draw[black!80,fill=white] (6,0) circle (.2cm);
\draw[very thick] (3.5,3.5) -- (3.5,-3.5) node [below] {Light to the South // of mast means 10};
\end{tikzpicture}
\end{document}
答案1
对于节点中的两行文本,您应该执行以下操作:
- 确定更多线条的节点样式,例如
\begin{tikzpicture}[every node/.style={align=left}]
- 而是
//
使用正确的代码来换行\\
完整代码(稍微重新排列了你的 MWE):
\documentclass[border=5pt, multi, tikz]{standalone}
%\usetikzlibrary{arrows.meta,decorations.markings}
%\usepackage{amsmath}
%\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}[
every node/.style={align=left}
]
% lines with nodes
\draw[very thick]
(0,0) node [left] {Light to the West\\ of mast means 00}
-- (7,0) node [right] {Light to the East\\ of mast means 11}
(3.5,3.5) node [above] {Light to the North\\ of mast means 01}
-- (3.5,-3.5) node [below] {Light to the South\\ of mast means};
% red circles
\draw[fill=red] (3.5,-3) circle (.2)
(3.5, 3) circle (.2);
% white circles
\draw[fill=white] (6,0) circle (.2)
(1,0) circle (.2);
% black square
\draw[fill=black] (3.3,-0.2) rectangle +(.4,0.4);
\end{tikzpicture}
\end{document}
图片: