0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【LaTeX】TikZで座標をアンカー名で指定した時に生じるずれの解消法

Last updated at Posted at 2022-09-26

ずれてしまう例

例えば,下のような図形を描くと,線が僅かにずれてしまっているのが分かる.

bad-sample.tex
\documentclass[a4j,dvipdfmx]{jsarticle}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \tikzset{box/.style={rectangle, draw, text centered, inner sep=1em}}; %rectangleをboxとしてスタイル定義
    \node[box](box1) at (0,0)    {box1};                                  %座標(0,0)を中心としてbox1を描画
    \node[box](box2) at (0,-1.5) {box2};                                  %座標(0,-1.5)を中心としてbox2を描画
    \draw(box1.south west) --(box2.north west);                           %box1の south west からbox2の north west まで線を引く
  \end{tikzpicture}
\end{document}

全体図

拡大図

このずれは,アンカーが線の外側に定義されていることに起因する.
下の画像1の✕印がアンカーの位置だ.

つまり,図形の線の太さは既定だと0.4pxであるから,その半分の0.2px分右にずらせば解決する.

解決例

good-sample.tex
\documentclass[a4j,dvipdfmx]{jsarticle}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \tikzset{box/.style={rectangle, draw, text centered, inner sep=1em}}; % rectangleをboxとしてスタイル定義
    \node[box](box1) at (0,0)    {box1};                                  % 座標(0,0)を中心としてbox1を描画
    \node[box](box2) at (0,-1.5) {box2};                                  % 座標(0,-1.5)を中心としてbox2を描画
    \node[coordinate, xshift=0.2](box1sw) at (box1.south west) {};        % box1の south west からx軸方向に0.2pxずらした位置を中心としてbox1swを描画(文章を指定していないため,何も描かれない)
    \node[coordinate, xshift=0.2](box2nw) at (box2.north west) {};        % box2の north west からx軸方向に0.2pxずらした位置を中心としてbox2nwを描画(文章を指定していないため,何も描かれない)
    \draw(box1sw) --(box2nw);                                             % box1swからbox2nwまで線を引く
  \end{tikzpicture}
\end{document}

拡大図

  1. https://ctan.org/pkg/pgf PGF Manual 786ページより引用

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?