我怎么才能tilt
不画rotate
矩形呢?我试图在另一个矩形内画一个矩形,但我希望次要的(较小的)矩形按(例如 25 度角)命名。
代码示例:
\documentclass{article}
\usepackage{tikz}
\usepackage{lscape}
\usepackage{nopageno}
\usepackage{pdflscape}
\usetikzlibrary{shapes.geometric,positioning}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,
}
\begin{document}
\begin{landscape}
\begin{tikzpicture}
\node at (0,0) [trapezium,
name=trapezium,
rounded corners,
line width=.05cm,
minimum width=5cm,
fill=blue!9!white,
minimum height=1cm,
draw=blue!50!white,
node distance=.05cm,
trapezium stretches=true] {};
\node [name=first,
rounded corners,
line width=.05cm,
fill=blue!9!white,
minimum width=5cm,
minimum height=1cm,
draw=blue!50!white,
node distance=.05cm,
below=of trapezium.south] {};
\node [name=second,
rounded corners,
line width=.05cm,
fill=blue!9!white,
minimum width=5cm,
minimum height=1cm,
draw=blue!50!white,
node distance=.05cm,
below=of first.south] {};
\node [name=third,
rounded corners,
line width=.05cm,
minimum width=5cm,
fill=blue!9!white,
draw=blue!50!white,
minimum height=1cm,
node distance=.05cm,
below=of second.south] {};
\node [name=fourth,
rounded corners,
line width=.05cm,
minimum width=5cm,
fill=blue!9!white,
draw=blue!50!white,
minimum height=1cm,
node distance=.05cm,
below=of third.south] {};
\node [circle,
fill=white,
xshift=-5mm,
name=firstCircle,
draw=blue!9!white,
minimum size=0.5cm] at (first.east) {};
\node [circle,
fill=white,
xshift=-5mm,
node distance=1cm,
draw=blue!9!white,
name=secondCircle,
minimum size=0.5cm] at (second.east) {};
\node [circle,
fill=white,
xshift=-5mm,
name=thirdCircle,
draw=blue!9!white,
minimum size=0.5cm,
node distance=20pt] at (third.east) {};
\node [name=forthCircle,
circle,
fill=white,
xshift=-5mm,
node distance=1cm,
draw=blue!9!white,
minimum size=0.5cm] at (fourth.east) {};
\node [name=fifth,
rectangle,
fill=white,
xshift=5mm,
draw=blue!9!white,
minimum width=.35cm,
minimum height=.8cm] at (first.west) {};
\end{tikzpicture}
\end{landscape}
\end{document}
(当前)输出示例:
所需输出的示例:
答案1
亲爱的 Thanos,正如 Qrrbrbirlbel 在上面评论的那样,一种方法是使用梯形而不是矩形。仅根据您的代码开始:
\documentclass{article}
\usepackage{tikz}
\usepackage{lscape}
\usepackage{nopageno}
\usepackage{pdflscape}
\usetikzlibrary{shapes.geometric,positioning}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,
}
\begin{document}
\begin{landscape}
\begin{tikzpicture}
\node at (0,0) [trapezium,
name=trapezium,
rounded corners,
line width=.05cm,
minimum width=5cm,
fill=blue!9!white,
minimum height=1cm,
draw=blue!50!white,
node distance=.05cm,
trapezium stretches=true] {};
\node [name=first,
rounded corners,
line width=.05cm,
fill=blue!9!white,
minimum width=5cm,
minimum height=1cm,
draw=blue!50!white,
node distance=.05cm,
below=of trapezium.south] {};
\node [name=second,
rounded corners,
line width=.05cm,
fill=blue!9!white,
minimum width=5cm,
minimum height=1cm,
draw=blue!50!white,
node distance=.05cm,
below=of first.south] {};
\node [name=third,
rounded corners,
line width=.05cm,
minimum width=5cm,
fill=blue!9!white,
draw=blue!50!white,
minimum height=1cm,
node distance=.05cm,
below=of second.south] {};
\node [name=fourth,
rounded corners,
line width=.05cm,
minimum width=5cm,
fill=blue!9!white,
draw=blue!50!white,
minimum height=1cm,
node distance=.05cm,
below=of third.south] {};
\node [circle,
fill=white,
xshift=-5mm,
name=firstCircle,
draw=blue!9!white,
minimum size=0.5cm] at (first.east) {};
\node [circle,
fill=white,
xshift=-5mm,
node distance=1cm,
draw=blue!9!white,
name=secondCircle,
minimum size=0.5cm] at (second.east) {};
\node [circle,
fill=white,
xshift=-5mm,
name=thirdCircle,
draw=blue!9!white,
minimum size=0.5cm,
node distance=20pt] at (third.east) {};
\node [name=forthCircle,
circle,
fill=white,
xshift=-5mm,
node distance=1cm,
draw=blue!9!white,
minimum size=0.5cm] at (fourth.east) {};
\node[trapezium,
trapezium left angle=70,
trapezium right angle=110,
fill=white,
xshift=6mm,
draw=blue!9!white,
inner xsep=0.3pt,%<- you can control shape width from here
minimum height=.8cm] at (first.west) {};
\node[trapezium,
trapezium left angle=70,
trapezium right angle=110,
fill=white,
xshift=12mm,
draw=blue!9!white,
inner xsep=0.3pt,%<- you can control shape width from here
minimum height=.8cm] at (first.west) {};
\end{tikzpicture}
\end{landscape}
\end{document}
答案2
我擅自创建了一种图片和路径图片方法。
pichouse
接受一个整数列表,创建一个带有一个屋顶(梯形)和与参数中的数字一样多的楼层(矩形)的图片。参数中的数字对应于每个矩形中的条纹(倾斜矩形)的数量。
因此,pic {house={6, 2, 2, 2}}
创建了一栋有四层的房子,其中顶层有六层,其他层有两条条纹。
第一个不会显示的节点 ( path only
) 具有自定义高度,其中.5mm
对应于节点距离,1cm
对应于楼层和屋顶的高度。此设置会创建一个包围整个房屋的节点,并采用图片的名称,同时还指定图片的放置位置和方式。长话短说:图片将像一个紧密贴合其周围的矩形节点一样处理
注意:path picture
仅当房屋(其楼层)没有旋转时才有效。
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,positioning}
\makeatletter % https://github.com/pgf-tikz/pgf/issues/1177
\newcommand*\tikzfixpathpicture{\tikz@transform\let\tikz@transform=\relax}
\makeatother
\tikzset{
house/stripes/.code={\tikzfixpathpicture
\fill[sharp corners, blue!9!white, even odd rule]
(path picture bounding box.south west)
rectangle (path picture bounding box.north east)
([xshift=+-5mm]path picture bounding box.east) circle[radius=+2.5mm]
[xslant=.3333, shift=(path picture bounding box.west)]
foreach \houseStripe in {1,...,#1}{
(5mm*\houseStripe,-3.5mm) rectangle ++ (2.5mm,7mm)};},
house/common/.style={
rounded corners, line width=+.5mm, minimum width=+5cm, minimum height=+1cm,
draw=blue!50!white, node contents=},
house/roof/.style={
house/common, shape=trapezium, fill=blue!9!white, trapezium stretches=true},
house/story/.style={house/common, shape=rectangle, node distance=+.5mm},
house/.pic={
\pgfmathtruncatemacro\stories{dim({#1})}
\node [house/common, path only, sharp corners,
minimum height={\stories*.5mm+(\stories+1)*1cm}, name=, alias=@];
\node [house/roof, name=-roof, at=(@.north), anchor=north, alias=@];
\foreach[count=\houseCount] \houseStripes in {#1}
\node[house/story, name=-story-\houseCount,alias=@,below=of @,
path picture=\tikzset{house/stripes=\houseStripes}];}}
\begin{document}
\tikz\pic {house={6,2,2,2}};
\begin{tikzpicture}
\pic (A) {house={6,2,2,2}};
\pic (B) [right=of A] {house={4,1}};
\draw[thick, red] (A-roof) -- (B-roof);
\draw (A) -- (B);
\end{tikzpicture}
\end{document}