
Ontem à noite eu criei este pedaço de LaTeX
, usando coordenadas relativas para unir nós com setas:
\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning} %for [above], [below] and shit.
\usetikzlibrary{arrows}
\usetikzlibrary{shapes}
\begin{document}
\begin{figure}[generic_scheme]
\tikzstyle{block}=[draw,shape=rectangle, minimum width=2.5cm,
minimum height=1cm]
\tikzstyle{f_arrow}=[->, thick]
\tikzstyle{d_arrow}=[<->, thick]
\begin{tikzpicture}[auto]
\node[block] (nuc) [] {Intel NUC};
\node[block] (power) [above=of nuc, yshift=0.5cm]
{Power\\Circuit};
\node[block] (smps) [left=of nuc, yshift=1.25cm] {SMPS};
\draw[f_arrow] (power.south) -- (nuc.north);
\draw[f_arrow] (power.west)++(0, -0.25) --
(smps.east)++(0, 0.25);
\draw[d_arrow] (nuc.west)++(0, 0.25) --
(smps.east)++(0, -0.25);
\end{tikzpicture}
\end{figure}
\end{document}
O resultado foi meio intrigante:
Hoje tentei esta forma alternativa usando yshift
em vez da coordenada relativa:
\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning} %for [above], [below] and shit.
\usetikzlibrary{arrows}
\usetikzlibrary{shapes}
\begin{document}
\begin{figure}[generic_scheme]
\tikzstyle{block}=[draw,shape=rectangle, minimum width=2.5cm,
minimum height=1cm]
\tikzstyle{f_arrow}=[->, thick]
\tikzstyle{d_arrow}=[<->, thick]
\begin{tikzpicture}[auto]
\node[block] (nuc) [] {Intel NUC};
\node[block] (power) [above=of nuc, yshift=0.5cm]
{Power\\Circuit};
\node[block] (smps) [left=of nuc, yshift=1.25cm] {SMPS};
\draw[f_arrow] (power.south) -- (nuc.north);
\draw[f_arrow] ([yshift=-0.25cm]power.west) --
([yshift=0.25cm]smps.east);
\draw[d_arrow] ([yshift=0.25cm]nuc.west) --
([yshift=-0.25cm]smps.east);
\end{tikzpicture}
\end{figure}
\end{document}
Então, minha pergunta seria: qual é a diferença entre essas peças aparentemente "idênticas" de LaTeX
? Estou perdendo algo trivial ao tentar entender como funciona relative coordinate
e yshift
funciona? Ou é apenas um bug na Ubuntu 14.04
instalação do meu estoque pdfTeX 3.1415926-2.5-1.40.14?
Responder1
O problema aqui é que usar
\draw[d_arrow] (nuc.west)++(0, 0.25) --
(smps.east)++(0, -0.25);
você énãoadicionando/subtraindo 0,25 das coordenadas sem afetar o caminho. Você está movendo o lápis, como mostra o exemplo simples a seguir (veja onde termina a linha em ambos os casos e onde resulta a ponta da seta):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) grid (6,3);
\draw (0,0)++(0.5,0.5) -- (2,2)++(0.5,0.5);
\draw[->] (3,0)++(0.5,0.5) -- (5,2)++(0.5,0.5);
\end{tikzpicture}
\end{document}
A sequência
\draw[->] (3,0)++(0.5,0.5) -- (5,2)++(0.5,0.5);
pode ser visto como:
- Mova o lápis para (3,0).
- Mova-o (mas sem desenhar) adicionalmente 0,5 nas coordenadas x e y.
- Comece a desenhar em (5,2).
- Mova o lápis adicionalmente 0,5 em ambas as coordenadas novamente (mas não há desenho agora).
- Coloque a(s) ponta(s) da seta.
Se você quiser adicionar os valores, use shifts ou a calc
biblioteca (talvez um exagero aqui):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw (0,0) grid (6,3);
\draw[->] ([shift={(0.5,0.5)}]0,0) -- ([shift={(0.5,0.5)}]2,2);
\draw[->] ( $ (3,0) +(0.5,0.5) $ ) -- ( $ (5,2) + (0.5,0.5) $ );
\end{tikzpicture}
\end{document}