我也抽空试了下...核心基本都是用decorations.pathreplacing
提供的brace
:
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\draw (0,.15) -- (0,0) node[left,yshift=.12cm] {Hello} -- (5,0) -- (5,.15) decorate [decoration={brace,amplitude=5pt}] { (0,.15) -- (5,.15) node[midway,yshift=.35cm] {50 dollars}};
\draw (0,-1+.15) -- (0,-1) node[left,yshift=.12cm] {Hello} -- (7,-1) -- (7,-1+.15) (0,-1-.15) -- (0,-1) (7,-1-.15) -- (7,-1) decorate [decoration={brace,,amplitude=5pt,mirror}] { (0,-1-.15) -- (7,-1-.15) node[midway,yshift=-.53cm] {70 dollars}};
\draw (5,-1+.15) decorate [decoration={brace,amplitude=5pt}] { -- (7,-1+.15) node[midway,yshift=.35cm] {? dollars}};
\draw[dashed] (5,0) -- (5,-1);
\end{tikzpicture}
\end{document}
@u3945 但是同时有个小建议:
应该使用markdown的围栏代码块将你的代码包围,否则会出现丢失\
的现象,你可以使用“补充回答”功能,让这部分代码正确高亮。
PS.国外不知道有没有线段图这一称呼,不知道有没有造好的轮子。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{ctex}
\begin{document}
\begin{tikzpicture}
% 画桃树的线段
\draw (0,0) -- (5.7,0);
\draw (0,0) -- (0,0.17);
\draw (5.7,0) -- (5.7,0.17);
\node at (-0.65,0.17) {桃树};
% 绘制一个大括号
\draw [decorate, decoration={brace, amplitude=5pt, raise=5pt}] (0,0) -- (5.7,0);
% 在大括号上方添加文字说明
\node at (2.85,0.6) {57棵};
% 画梨树的线段
\draw (0,-1.0) -- (7.3,-1.0);
\draw (0,-1.0) -- (0,-0.83);
\draw (7.3,-1.0) -- (7.3,-0.83);
\draw (5.7,-1.0) -- (5.7,-0.83);
\node at (-0.65,-0.83) {梨树};
% 绘制一条虚线
\draw[dashed] (5.7,0) -- (5.7,-1.0);
% 绘制一个大括号
\draw [decorate, decoration={brace, amplitude=5pt, raise=5pt}] (5.7,-1.0) -- (7.3,-1.0);
% 在大括号上方添加文字说明
\node at (6.5,-0.4) {多16棵};
% 绘制一个大括号
\draw [decorate, decoration={brace, amplitude=10pt, raise=5pt, mirror}] (0,-0.84) -- (7.3,-0.84);
% 在大括号下方添加文字说明
\node at (3.65,-1.6) {?棵};
\end{tikzpicture}
\end{document}
供参考。
%引用微信群大佬latexer代码,非常感谢!!!
documentclass{standalone}
usepackage{xeCJK}
usepackage{tikz}
usepackage{tkz-euclide}
usetikzlibrary{decorations.pathreplacing}
begin{document}
\small
\begin{tikzpicture}[>=latex,scale=1.0]
\draw(0,0)node [left=5pt]{小鸡}--++(2.6,0);
\draw[decorate,decoration={brace,amplitude=7pt},yshift=2pt]
(0,0)--(2.6,0)node[midway,above=4pt]{26只};
\draw(0,-1.0)node [left=5pt]{小鸭}--++(5,0);
\draw[decorate,decoration={brace,amplitude=7pt},yshift=2pt]
(2.6,-1.0)--(5,-1.0)node[midway,above=4pt]{多24只};
\draw[densely dashed](2.6,0)--++(0,-1.0);
\draw[decorate,decoration={brace,amplitude=7pt},yshift=-2pt]
(5,-1.0)--(0,-1.0)node[midway,below=8pt]{?只};
\end{tikzpicture}
end{document}
让代码好改点? declare function=
\documentclass[tikz,border=1em]{standalone}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\usepackage{ctex}
\begin{document}
\begin{tikzpicture}[scale=1,declare function={ts=5.7;ls=7.3;jj=1.1;}]
\node at (0,jj) [shift={(-1.5em,0.5em)}] {桃树};
\node at (0,0) [shift={(-1.5em,0em)}] {梨树};
\draw (0,0) -- (ls,0); % 梨树
\draw (0,jj) -- (ts,jj); % 桃树
\draw[dashed] (ts,0) -- (ts,jj); % 虚线
\foreach \tbq/\lbq in {0/0,ts/ts,0/ls} {
\draw (\tbq,jj) -- (\tbq,{jj+0.2});
\draw (\lbq,0) -- (\lbq,0.2);
}
\draw[decorate,decoration={calligraphic brace,amplitude=5pt},yshift=0.5em]
(0,jj)--(ts,jj) node[midway,above=1ex]{57棵};
\draw[decorate,decoration={calligraphic brace,amplitude=5pt},yshift=0.5em]
(ts,0)--(ls,0) node[midway,above=1ex]{多16棵};
\draw[decorate,decoration={calligraphic brace,amplitude=10pt,mirror}]
(0,0)--(ls,0) node[midway,below={1ex+5pt}]{?棵};
\end{tikzpicture}
\end{document}
谢谢你
@u3945 所以你修改原自答并用上 markdown 语法了吗(doge)
并在代码前后加上三个反引号
`
即可