我对显示元素间间距的文本有疑问,我希望它与我的结构处于相同的方向,有没有简单的 Tikz 解决方案?
代码 :
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\tdplotsetmaincoords{40}{-30}
\begin{document}
\begin{tikzpicture}[tdplot_main_coords]
\def \r{0.5};
\def \d{1.5};
\def \nx{2};
\def \ny{2};
\def \bord{0.11};
\def \hsub{0.1};
\definecolor{cuivre}{rgb}{0.9,0.7,0.4};
\definecolor{ceram}{rgb}{0.92,0.95,0.95};
%masse
\filldraw[fill=gray] (\d-\r-\bord,\d-\r-\bord,-\hsub)
--++ (\nx*\d-\r/2,0,0)
--++ (0,\ny*\d-\r/2,0)
--++ (-\nx*\d+\r/2,0,0)
-- cycle;
%cadre
\filldraw[fill=cuivre] (\d-\r-\bord,\d-\r-\bord,0)
--++ (\nx*\d-\r/2,0,0)
--++ (0,\ny*\d-\r/2,0)
--++ (-\nx*\d+\r/2,0,0)
-- cycle;
%sub1
\filldraw[fill=ceram] (\d-\r-\bord,\d-\r-\bord,0)
--++ (0,0,-\hsub)
--++ (0,\ny*\d-\r/2,0)
--++ (0,0,\hsub)
-- cycle;
%sub2
\filldraw[fill=ceram] (\d-\r-\bord,\d-\r-\bord,0)
--++ (0,0,-\hsub)
--++ (\nx*\d-\r/2,0,0)
--++ (0,0,\hsub)
-- cycle;
%trous
\foreach \x in {1,...,\nx}{
\foreach \y in {1,...,\ny}{
\filldraw[fill=ceram] (\d*\x,\d*\y,0) circle (\r);
}
}
\foreach \x in {2,...,\nx}{
\foreach \y in {2,...,\ny}{
\filldraw[fill=ceram] (\d*\x-\d/2,\d*\y-\d/2,0)
circle (\r);
}
}
%espace inter trou 1
\draw[dashed] (\d, \nx*\d,\hsub) --++ (0,1.5,0);
\draw[dashed] (2*\d, \nx*\d,\hsub) --++ (0,1.5,0);
\draw[<->] (\d, \nx*\d+1.5,\hsub) -- (2*\d, \nx*\d+1.5,\hsub) node
[font=\footnotesize,midway, fill=white, anchor=center]{1.5mm};
\end{tikzpicture}
\end{document}
答案1
只需添加sloped
作为最后一个节点的参数。above
使文本不超过线。
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\tdplotsetmaincoords{40}{-30}
\begin{document}
\begin{tikzpicture}[tdplot_main_coords]
\def \r{0.5};
\def \d{1.5};
\def \nx{2};
\def \ny{2};
\def \bord{0.11};
\def \hsub{0.1};
\definecolor{cuivre}{rgb}{0.9,0.7,0.4};
\definecolor{ceram}{rgb}{0.92,0.95,0.95};
%masse
\filldraw[fill=gray] (\d-\r-\bord,\d-\r-\bord,-\hsub)
--++ (\nx*\d-\r/2,0,0)
--++ (0,\ny*\d-\r/2,0)
--++ (-\nx*\d+\r/2,0,0)
-- cycle;
%cadre
\filldraw[fill=cuivre] (\d-\r-\bord,\d-\r-\bord,0)
--++ (\nx*\d-\r/2,0,0)
--++ (0,\ny*\d-\r/2,0)
--++ (-\nx*\d+\r/2,0,0)
-- cycle;
%sub1
\filldraw[fill=ceram] (\d-\r-\bord,\d-\r-\bord,0)
--++ (0,0,-\hsub)
--++ (0,\ny*\d-\r/2,0)
--++ (0,0,\hsub)
-- cycle;
%sub2
\filldraw[fill=ceram] (\d-\r-\bord,\d-\r-\bord,0)
--++ (0,0,-\hsub)
--++ (\nx*\d-\r/2,0,0)
--++ (0,0,\hsub)
-- cycle;
%trous
\foreach \x in {1,...,\nx}{
\foreach \y in {1,...,\ny}{
\filldraw[fill=ceram] (\d*\x,\d*\y,0) circle (\r);
}
}
\foreach \x in {2,...,\nx}{
\foreach \y in {2,...,\ny}{
\filldraw[fill=ceram] (\d*\x-\d/2,\d*\y-\d/2,0)
circle (\r);
}
}
%espace inter trou 1
\draw[dashed] (\d, \nx*\d,\hsub) --++ (0,1.5,0);
\draw[dashed] (2*\d, \nx*\d,\hsub) --++ (0,1.5,0);
\draw[<->] (\d, \nx*\d+1.5,\hsub) -- (2*\d, \nx*\d+1.5,\hsub) node
[font=\footnotesize,midway, fill=white, anchor=center,sloped, above]{1.5mm}; %here's the trick
\end{tikzpicture}
\end{document}