在他们的回答中,“扎科”和“懒惰的松鼠”慷慨地帮助我开始使用tikz
(我以前从未使用过它,它对我来说是令人畏惧的)。
我知道,下面的问题有点不努力,需要“阅读手册”的陈述。但我正在完成我的论文,如果有人能慷慨地帮助我编写代码,那将对我有很大帮助虚线箭头(向左向上)如下图所示:
我希望箭头能形成一条从“传统电容器”点到“超级电容器”点的垂直“路径”。理想情况下,当我改变这些点的位置时,箭头会自动改变——我的顾问决定它们应该去哪里!
感谢您考虑提供帮助。这是我的 MWE:
\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{siunitx}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tikzpicture}[
> = Stealth,
dot/.style = {circle, fill, minimum size=5pt, inner sep=0pt},
N/.style = {align=left},
every label/.style = {label distance = 0pt, N},
lbl/.style 2 args={append after command={
(\tikzlastnode)node[right=5pt,inner sep=0pt] (tmp){#1}
(tmp.south west)
node[anchor=north west,font=\footnotesize,inner sep=0pt]{#2}}}
]
\path[local bounding box=dots] (1,3) node[dot,lbl={battery}{second line}]{}
(2,2) node[dot,lbl={supercapacitor}{second line}]{}
(3,1) node[dot,lbl={conventional capacitor}{second line}]{};
%
\draw [<->] ([yshift=1cm]dots.north-|0,0)
|- ([xshift=5mm]dots.east|-0,0)
node[pos=0.25, N, above,rotate=90] {energy density (Wh/kg)}
node[pos=0.75, N, below] {power density (W/kg)};
\end{tikzpicture}
\caption{Caption}
\label{fig:ragone}
\end{figure}
\end{document}
答案1
给这些点命名,以便于你引用它们,例如
dotsup
和dotconv
:node[dot,lbl={supercapacitor}{second line}](dotsup){} node[dot,lbl={conventional capacitor}{second line}](dotconv){}
绘制一个带角的箭头:
\draw[dashed,->] (dotconv) -| (dotsup);
要画两个直箭头,可以用 来参考角点
(dotconv-|dotsup)
。\draw[dashed,->] (dotconv) -- (dotconv-|dotsup); \draw[dashed,->] (dotconv-|dotsup) -- (dotsup);
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[
> = Stealth,
dot/.style = {circle, fill, minimum size=5pt, inner sep=0pt},
N/.style = {align=left},
every label/.style = {label distance = 0pt, N},
lbl/.style 2 args={append after command={
(\tikzlastnode)node[right=5pt,inner sep=0pt] (tmp){#1}
(tmp.south west)
node[anchor=north west,font=\footnotesize,inner sep=0pt]{#2}}}
]
\path[local bounding box=dots] (1,3) node[dot,lbl={battery}{second line}]{}
(2,2) node[dot,lbl={supercapacitor}{second line}](dotsup){}
(3,1) node[dot,lbl={conventional capacitor}{second line}](dotconv){};
\draw [<->] ([yshift=1cm]dots.north-|0,0)
|- ([xshift=5mm]dots.east|-0,0)
node[pos=0.25, N, above,rotate=90] {energy density (Wh/kg)}
node[pos=0.75, N, below] {power density (W/kg)};
\draw[dashed,->] (dotconv) -- (dotconv-|dotsup);
\draw[dashed,->] (dotconv-|dotsup) -- (dotsup);
\end{tikzpicture}
\end{document}
答案2
这是 Zarko 的上述回答,经过了一些简化,可能更适合初学者。
\documentclass[oneside,11pt]{book}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{figure}[!ht]
\centering
\begin{tikzpicture}[> = Stealth,
dot/.style={circle,fill=blue,minimum size=5pt,inner sep=0pt}]
\draw[->] (0,0)--(7,0) node[pos=.5,below]
{energy density (Wh/kg)};
\draw[->] (0,0)--(0,5) node[pos=.5,rotate=90,above]
{power density (Wh/kg)};
\path
(1,3) node[dot] (A) {}
(2,2) node[dot] (B) {}
(3,1) node[dot] (C) {};
\path[nodes={right=1mm,align=left}]
(A) node{battery\\[-1.5mm]\footnotesize second line}
(B) node{supercapacitor\\[-1.5mm]\footnotesize second line}
(C) node{conventional capacitor\\[-1.5mm]\footnotesize second line};
\draw[densely dashed,->,magenta] (C)--(C-|B);
\draw[densely dashed,->,magenta] (C-|B)--(B);
\end{tikzpicture}
\caption{Caption}
\label{fig:ragone}
\end{figure}
\end{document}
更新:我们可以通过这个微小的改变将点和第一行文本对齐:
\path
(A)
+(1mm,0) node[right]{battery}
+(1mm,-3.5mm) node[right]{\footnotesize second line}
(B)
+(1mm,0) node[right]{supercapacitor}
+(1mm,-3.5mm) node[right]{\footnotesize second line}
(C)
+(1mm,0) node[right]{conventional capacitor}
+(1mm,-3.5mm) node[right]{\footnotesize second line}
;
答案3
呵呵,@gernot 更快(+1)...我花了一些时间重新排列你的代码并在其中写下注释,否则解决方案是类似的:你需要命名你喜欢用箭头连接的节点,然后根据需要在它们之间画线:
\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{siunitx}
\begin{document}
\begin{figure}[!ht]
\centering
\begin{tikzpicture}[
> = Stealth,
dot/.style = {circle, fill, minimum size=5pt, inner sep=0pt},
N/.style = {align=left},
lbl/.style 2 args = {append after command={
(\tikzlastnode) node[right=5pt,inner sep=0pt] (tmp){#1}
(tmp.south west) node[anchor=north west,font=\footnotesize,inner sep=0pt]{#2}}}
]
% axes
\draw[<->] (0,5) |- (7,0)
node[pos=0.25, N, above,rotate=90] {energy density (Wh/kg)}
node[pos=0.75, N, below] {power density (Wh/kg)};
% nodes
\path (1,3) node (a) [dot,lbl={battery}{second line}]{} % aded name (a)
(2,2) node (b) [dot,lbl={supercapacitor}{second line}]{} % aded name (b)
(3,1) node (c) [dot,lbl={conventional capacitor}{second line}]{}; % aded bane (c)
% dashed lines between nodes (c) and (b)
\draw[densely dashed, ->] (c) -- (c -| b);
\draw[densely dashed,->] (c -| b) -- (b);
\end{tikzpicture}
\caption{Caption}
\label{fig:ragone}
\end{figure}
\end{document}
答案4
我简单地放了一些我非常喜欢的用 Mathcha 完成的代码......
%% Compile and read me!
\documentclass[a4paper,12pt]{article}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage{tikz}
\usepackage{siunitx}
\begin{document}
\begin{figure}[!h]
\centering
\tikzset{every picture/.style={line width=0.75pt}}
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw [color={rgb, 255:red, 255; green, 0; blue, 255 } ,draw opacity=1 ] [dash pattern={on 4.5pt off 4.5pt}] (430.47,241.04) -- (364.52,241.04) ;
\draw [shift={(361.52,241.04)}, rotate = 360] [fill={rgb, 255:red, 255; green, 0; blue, 255 } ,fill opacity=1 ][line width=0.08] [draw opacity=0] (10.72,-5.15) -- (0,0) -- (10.72,5.15) -- (7.12,0) -- cycle ;
\draw (240,293) -- (240,69) ;
\draw [shift={(240,66)}, rotate = 450] [fill={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.08] [draw opacity=0] (10.72,-5.15) -- (0,0) -- (10.72,5.15) -- (7.12,0) -- cycle ;
\draw (240,293) -- (606.52,293) ;
\draw [shift={(609.52,293)}, rotate = 180] [fill={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.08] [draw opacity=0] (10.72,-5.15) -- (0,0) -- (10.72,5.15) -- (7.12,0) -- cycle ;
\draw [fill={rgb, 255:red, 0; green, 0; blue, 0 } ,fill opacity=1 ] (427.43,241.04) .. controls (427.43,239.36) and (428.79,238) .. (430.47,238) .. controls (432.15,238) and (433.52,239.36) .. (433.52,241.04) .. controls (433.52,242.72) and (432.15,244.09) .. (430.47,244.09) .. controls (428.79,244.09) and (427.43,242.72) .. (427.43,241.04) -- cycle ;
\draw [fill={rgb, 255:red, 0; green, 0; blue, 0 } ,fill opacity=1 ] (298.43,161.04) .. controls (298.43,159.36) and (299.79,158) .. (301.47,158) .. controls (303.15,158) and (304.52,159.36) .. (304.52,161.04) .. controls (304.52,162.72) and (303.15,164.09) .. (301.47,164.09) .. controls (299.79,164.09) and (298.43,162.72) .. (298.43,161.04) -- cycle ;
\draw [fill={rgb, 255:red, 0; green, 0; blue, 0 } ,fill opacity=1 ] (358.43,200.04) .. controls (358.43,198.36) and (359.79,197) .. (361.47,197) .. controls (363.15,197) and (364.52,198.36) .. (364.52,200.04) .. controls (364.52,201.72) and (363.15,203.09) .. (361.47,203.09) .. controls (359.79,203.09) and (358.43,201.72) .. (358.43,200.04) -- cycle ;
\draw [color={rgb, 255:red, 255; green, 0; blue, 255 } ,draw opacity=1 ] [dash pattern={on 4.5pt off 4.5pt}] (361.52,241.04) -- (361.52,207.09) ;
\draw [shift={(361.52,204.09)}, rotate = 450] [fill={rgb, 255:red, 255; green, 0; blue, 255 } ,fill opacity=1 ][line width=0.08] [draw opacity=0] (10.72,-5.15) -- (0,0) -- (10.72,5.15) -- (7.12,0) -- cycle ;
% Text Node
\draw (338,300) node [anchor=north west][inner sep=0.75pt] [align=left] {energy density (Wh/kg)};
% Text Node
\draw (207.5,252.5) node [anchor=north west][inner sep=0.75pt] [rotate=-270] [align=left] {power density (Wh/kg)};
% Text Node
\draw (309,152) node [anchor=north west][inner sep=0.75pt] [align=left] {battery};
% Text Node
\draw (308,168) node [anchor=north west][inner sep=0.75pt] [align=left] {{\footnotesize second line}};
% Text Node
\draw (369,194) node [anchor=north west][inner sep=0.75pt] [align=left] {supercapacitor};
% Text Node
\draw (368,210) node [anchor=north west][inner sep=0.75pt] [align=left] {{\footnotesize second line}};
% Text Node
\draw (440,233) node [anchor=north west][inner sep=0.75pt] [align=left] {conventional capacitor};
% Text Node
\draw (439,249) node [anchor=north west][inner sep=0.75pt] [align=left] {{\footnotesize second line}};
\end{tikzpicture}
\caption{Caption}
\label{fig:ragone}
\end{figure}
\end{document}