答案1
在 TikZ 中,有多种方法可以制作这样的图表。这里我展示了两种截然不同的方法。代码中有很多注释,所以请查看这些注释,如果有任何不清楚的地方可以询问。我还鼓励使用手册作为参考。
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{
arrows.meta, % for defining arrow tips
decorations.markings, % for adding arrow tips and other things in the middle of a line
calc % for coordinate calculations (i.e. "($(..) + (..)$)" syntax)
}
\tikzset{
% here I define some styles
% styles can make a diagram easier to modify, as you just need to change the definition of
% a style, and not every use of it
%
% /.tip is for defining arrow tips
MyTip/.tip={Straight Barb},
LineTip/.tip={Bar[width=6mm]},
%
MyLine/.style={ultra thick,line join=bevel},
% sloped means that the text is placed parallel to the line on which
% it is placed, and "above" has the obvious meaning
MyNode/.style={sloped,above}
}
\begin{document}
\begin{tikzpicture}
% draw horizontal line at the top, using the MyLine style defined above
\draw [MyLine] (-2,0) --
% when a node or coordinate is added right after "--", in "(a) -- (b)", it is
% placed halfway between the points a and b
% the label option is for placing text near the coordinate
coordinate [label=above:$T_{m}^{\mathrm{F}} + T_{m}^{\mathrm{SH}}$]
% name the coordinate "O", which is used later
(O)
(2,0);
% now we draw the ray, again using the MyLine style
\draw [
MyLine,
% now we define decorations for the line, see chapter 48.4 in the manual
decoration={
% the type of decoration is "markings"
markings,
% add a mark:
% "at position <fraction>" is somewhat self explanatory -- the mark is
% placed 10% of the way along the line
% after "with" follows the definition of the mark
% "\arrow{<arrow tip specification>}" does what you might thing, adding
% an arrow tip pointing along the line
mark=at position 0.1 with \arrow{MyTip},
% Here we do something different. Instead of an arrow tip we add drawing commands
% in a pair of braces. The origin is the point on the path that is chosen,
% and the positive x-axis is tangential to the line.
mark=at position 0.1 with { \draw [MyLine] (0,3mm) -- (0,-3mm); },
mark=at position 0.2 with \arrow{MyTip},
mark=at position 0.65 with \arrow{MyTip},
mark=at position 0.65 with { \draw [MyLine] (0,3mm) -- (0,-3mm) node[below left,inner sep=0pt] {$T_{f}^{\mathrm{F}}$};},
mark=at position 0.7 with { \draw [MyLine] (0,3mm) -- (0,-3mm) node[below left,inner sep=0pt] {$T_{f}^{\mathrm{SH}}$};},
mark=at position 1 with \arrow{MyTip},
},
% Because we want the decoration in addition to the line itself, we
% tell TikZ to first draw the line, and then in a separate step afterwards
% (hence "post") we draw the decoration.
postaction={decorate}
]
% Now for the specification of the line.
% Could have made this relative to O, but
(-3,-5) --
% place the I_0 and I_1 nodes, using the MyNode style defined above
% pos=<fraction> is similar to the decoration above, it defines where
% along the line the node should be placed.
% But here the fraction is between (-3,-5) and (O) (the next coordinate)
node[MyNode,pos=0.1] {$I_0$}
node[MyNode,pos=0.3] {$I_1$}
(O) --
node[MyNode,pos=0.12] {$I_2$}
node[MyNode,pos=0.6] {$I_3$}
(3,-5)
;
\end{tikzpicture}
% second method
\begin{tikzpicture}[
% the angle of the line is defined using polar coordinates
% for convenience, save that angle as a function
% to change the angle of the line, just change the value
declare function={Angle=60;}
]
% The method is is quite different. Instead of drawing the whole line in one,
% I draw it part by part.
\draw
% You add an arrow tip to a line with the option "-ArrowTipName". But it is also
% possible to have multiple tips on the same line. Here I use both two tips defined
% above, first the normal arrow, then one that is just a straight line
[MyLine,-{MyTip[] LineTip}]
% the start coordinate is arbitrary
(0,0) -- node[MyNode] {$I_0$}
% the "++" indicates that this coordinate is relative to the previous one,
% and the colon indicates that this is polar cooordinates: (<angle>:<radius>)
% using the Angle-function defined above, and setting the length to 1cm
++(Angle:1cm)
% at the end I add a named coordinate, which is used as the starting point
% off the next line segment
coordinate (tmp);
% the only new thing here is shorten >=length. "shorten >" and "shorten <" is
% perhaps intended to shorten the end and start of a line, but it can also
% be used with negative lengths to extend a line. This is done here to cover
% a small gap after the arrow tip. Test without that setting to see the difference.
\draw [MyLine,-MyTip, shorten >=-1pt] (tmp) -- node[MyNode] {$I_1$} ++(Angle:1cm) coordinate (tmp);
\draw [MyLine] (tmp) -- ++(Angle:3cm) coordinate (tmp);
% Here the horizontal line at the top is drawn
% The syntax with the dollar signs is used to calculate coordinates
\draw [MyLine] ($(tmp)-(2,0)$) -- node[above] {$T_{m}^{\mathrm{F}} + T_{m}^{\mathrm{SH}}$} ($(tmp)+(2,0)$);
\draw [MyLine,-MyTip] (tmp) -- node[MyNode] {$I_2$} ++(-Angle:1.5cm) coordinate (tmp);
% The following line shows another method of drawing the short perpendicular lines.
% Because the direction of the line is here defined by -Angle, the direction
% of a line perpendicular to it is -Angle-90, or -Angle+90 degrees.
\draw [MyLine] ($(tmp)+(-Angle+90:3mm)$) -- ($(tmp)+(-Angle-90:3mm)$)
% here the node is placed after the final coordinate of the path
% so it is positioned at that point, but due to "below left", it is placed as such
node[below left,inner sep=0pt] {$T_{f}^{\mathrm{F}}$};
% nothing new in the last few lines
\draw [MyLine] (tmp) -- ++(-Angle:8mm) coordinate (tmp);
\draw [MyLine] ($(tmp)+(-Angle+90:3mm)$) -- ($(tmp)+(-Angle-90:3mm)$) node[below left,inner sep=0pt] {$T_{f}^{\mathrm{SH}}$};
\draw [MyLine,-MyTip] (tmp) -- node[MyNode] {$I_3$} ++(-Angle:2.7cm);
\end{tikzpicture}
\end{document}
答案2
当你在等待一些指针或示例来开始使用 TikZ 时,这里有一个用元帖子,您可能也想了解一下。我已将希望有用的评论纳入其中。
\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
% set the 1/2 angle between incoming and outgoing rays
theta = 36;
% define the point at the bottom left
z0 = 180 down rotated -theta;
% define four more points relative to this
z1 = 1/4[z0, origin];
z2 = 1/2[z0, origin];
z3 = 1/3[origin, z4];
z4 = z0 rotated 2 theta;
% draw arrows from point to point
drawarrow z0--z1;
drawarrow z1--z2;
drawarrow z2--origin--z3;
drawarrow z3--z4;
% draw the base line, with a thick pen
draw (left--right) scaled 60 withpen pencircle scaled 1;
% save the cross pieces as paths (so they can be used for the labels)
path t[];
t1 = (down--up) scaled 20 rotated angle z1 shifted z1;
t2 = (down--up) scaled 20 rotated angle z3 shifted z3;
t3 = (down--up) scaled 20 rotated angle z3 shifted 1/5[z3,z4];
% draw the cross pieces, erasing under the third one
draw t1;
draw t2;
undraw t3 withpen pencircle scaled 3;
draw t3;
% add labels
label.top("$T_m^F+T_m^{SH}$", origin);
label.llft("$T_f^f$", point 0 of t2);
label.llft("$T_f^{SH}$", point 0 of t3);
label.ulft("$I_0$", 1/2[z0,z1]);
label.ulft("$I_1$", 1/2[z1,z2]);
label.urt("$I_2$", 1/2[origin,z3]);
label.urt("$I_3$", 1/2[z3,z4]);
% You could rotate these labels but I think they look better unrotated...
% Here's one way:
% label.ulft(textext("$I_0$") rotated 90-theta, 1/2[z0,z1]);
endfig;
\end{mplibcode}
\end{document}
这被包裹在内luamplib
,因此您需要用它进行编译lualatex
,或者将其改编为普通的 Metapostgmp
或pdflatex
。