将文本的第一行与 tikz 中的节点对齐

将文本的第一行与 tikz 中的节点对齐

Zarko 的回答在这里,我使用以下示意图tikz

\documentclass[oneside,11pt]{book}

\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage{graphicx}
\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}
                        ]
\draw[<->]  (0,4.5) |-  (7,0)
    node[pos=0.25, N, above,rotate=90]     {energy density (Wh/kg)}
    node[pos=0.75, N, below]    {power density (W/kg)};                     
%
\node[dot, label=right:battery\\{\footnotesize second line}] at (1,3) {};
\node[dot, label=right:supercapacitor\\{\footnotesize second line}] at (2,2) {};
\node[dot, label=right:conventional capacitor\\{\footnotesize second line}] at (3,1) {};
    \end{tikzpicture}
  \caption{Caption}
  \label{fig:ragone}
\end{figure}

\end{document} 

姆韦

如何使第一行文本与节点/点垂直对齐?

另外,有没有简单的方法可以控制文本的行距?

答案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}[!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}

在此处输入图片描述

相关内容