![如何在节点内创建新行](https://linux22.com/image/474484/%E5%A6%82%E4%BD%95%E5%9C%A8%E8%8A%82%E7%82%B9%E5%86%85%E5%88%9B%E5%BB%BA%E6%96%B0%E8%A1%8C.png)
这是我的代码:
\tikzset{Dot/.style={
circle,
fill,
inner sep=2pt, % adjust the size of the dot as needed
}
}
\begin{figure}[h!]
\centering
\begin{subfigure}[t]{0.49\textwidth}
\centering
\begin{tikzpicture}
\draw
(0,0) node (v0) {}
(v0)--++(3,-1) coordinate(v1)
(v0) ++(3,-1) node[pos=0.2][above=0.25cm] {Linha 1}
(v1) node [Dot] {} node[below = 0.2] {Subestação
virtual}
(v1)--++(3,-1) coordinate(v2)
;
\draw[blue] (v1)--++(3,1) node[pos=0.8][above=0.25cm] {Linha 2};
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[t]{0.49\textwidth}
\centering
\begin{tikzpicture}
\draw
(0,0) node (v0) {} % placing the left most source
(v0)--++(3,-1) coordinate(v1)
(v0) ++(3,-1) node[pos=0.2][above=0.25cm] {Linha 1}
(v1) node [Dot] {} node[below = 0.2] {Subestação virtual}
;
\draw[blue] (v1) --++(3,1) node[pos=0.8][above=0.25cm] {Linha 2};
\draw[red] (v1) --++(3,-1) node[pos=0.8][above=0.25cm] {Linha 3};
\end{tikzpicture}
\end{subfigure}
\caption{222.}
\label{Conexão Central termoelétrica - Substação1}
\end{figure}
我尝试使用双 \ 在 Subestação 和 virtual 之间创建新的线条,但出现错误。另外,你们知道如何让线条不与 Dot 的中心相交,只与其边缘相交(方向相同)吗?
答案1
您没有提供文档类。我用作standalone
示例。您需要为节点设置文本宽度键。我调整了代码tikz
,这样看起来更时髦。如果(v1)
与点而不是坐标相关联node
,则以下绘图将不会与其相交。
\documentclass{standalone}
\usepackage{tikz}
\tikzset{Dot/.style={
circle,
fill,
inner sep=2pt, % adjust the size of the dot as needed
}
}
\begin{document}
\begin{tikzpicture}
\draw (0,0) coordinate (v0)
-- ++(3,-1)
node [pos=0.2,above=0.25cm] {Linha 1}
node (v1) [Dot] {}
node [text width=1.7cm,below = 0.2cm] {Subestação virtual}
-- ++(3,-1) coordinate (v2) ;
\draw [blue] (v1) -- ++ (3,1) node[blue,pos=0.8,above=0.25cm]{Linha 2};
\end{tikzpicture}
\begin{tikzpicture}[xshift=6.1cm]
\draw (0,0) coordinate (v0)
-- ++(3,-1)
node [pos=0.2,above=0.25cm] {Linha 1}
node (v1) [Dot] {}
node [text width=1.7cm,below = 0.2cm] {Subestação virtual}
++(3,-1) coordinate (v2) ;
\draw [blue] (v1) -- ++ (3,1) node[blue,pos=0.8,above=0.25cm]{Linha 2};
\draw [red] (v1) -- (v2) node[red,pos=0.8,above=0.25cm]{Linha 2};
\end{tikzpicture}
\end{document}
答案2
要使用换行符,必须\\
使用选项指定对齐方式,align
该选项可以取值为left
、right
、center
、flush left
、flush right
和。以下是两个示例及其代码结果。flush center
justify
none
\documentclass[tikz]{standalone}
\begin{document}
\tikzset{Dot/.style={
circle,
fill,
inner sep=2pt, % adjust the size of the dot as needed
}
}
\begin{tikzpicture}
\draw
(0,0) node (v0) {} % placing the left most source
(v0)--++(3,-1) coordinate(v1)
(v0) ++(3,-1) node[pos=0.2][above=0.25cm] {Linha 1}
(v1) node [Dot] {} node[below = 0.2,align=left] {Subestação\\ virtual}
;
\draw[blue] (v1) --++(3,1) node[pos=0.8][above=0.25cm] {Linha 2};
\draw[red] (v1) --++(3,-1) node[pos=0.8][above=0.25cm] {Linha 3};
\end{tikzpicture}
\begin{tikzpicture}
\draw
(0,0) node (v0) {} % placing the left most source
(v0)--++(3,-1) coordinate(v1)
(v0) ++(3,-1) node[pos=0.2][above=0.25cm] {Linha 1}
(v1) node [Dot] {} node[below = 0.2,align=center] {Subestação\\ virtual}
;
\draw[blue] (v1) --++(3,1) node[pos=0.8][above=0.25cm] {Linha 2};
\draw[red] (v1) --++(3,-1) node[pos=0.8][above=0.25cm] {Linha 3};
\end{tikzpicture}
\end{document}