在固定宽度的节点中插入长文本

在固定宽度的节点中插入长文本

使用以下代码,是否可以将长文本(在节点中)插入具有特定背景颜色、具有特定定义宽度和可容纳长文本的高度的框架框内。

    \documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{1}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (6.2,0) node [black, xshift=.3cm, yshift=0cm] {$x$};
\draw [thick,-latex](0,0) -- (0,5) node [black, xshift=0cm, yshift=.3cm] {$u$};
\draw [ultra thick,blue] (0,2.84) -- +(-40:4.44cm) node [pos=.5,red] {x} node [pos=.5, xshift=4.8cm, yshift=.2cm] {very very very very very very very long long long long long long long text} node [pos=0,circle, draw, black, fill=black, scale=0.5]{}  node [pos=1,circle, draw, black, fill=black, scale=0.5]{};
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

让它看起来像这样

在此处输入图片描述

答案1

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{1}

\begin{tikzpicture}[
    dot/.style = {circle, fill, node contents={}},
    every pin/.append style = {pin distance=9mm, pin edge={black, semithick},
                               text width=24mm, fill=orange!20}
                    ]
\draw [thick,-latex](0,0) -- (6.2,0) node [black, xshift=.3cm, yshift=0cm] {$x$};
\draw [thick,-latex](0,0) -- (0,5) node [black, xshift=0cm, yshift=.3cm] {$u$};
\draw [ultra thick,blue] (0,2.84) --
    node [dot,pin=60:very very very very very very very long long long long long long long text] + (-40:4.44cm);
\end{tikzpicture}

\end{frame}
\end{document}

给出:

在此处输入图片描述

这就是你要找的吗?

在上面的 mwe 中,我定义了dot曲线上黑色圆圈的节点样式,并添加了文本作为pin此节点的 pin 样式,其中包括text width=<width>选项。此选项会自动将长文本拆分为多行(长度由 确定<width>

补充:

对图钉和文本锚点的更多控制使解决方案能够奎伯比尔贝尔回答问题tikz 调节销锚. 对你的问题的采纳是:

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}

\begin{document}
\begin{frame}[fragile,t]
\frametitle{1}

\begin{tikzpicture}[
    dot/.style = {circle, fill, outer sep=0pt, node contents={}},
aligned pin/.style args={[#1]#2:#3}%
    {pin={[pin distance=9mm, pin edge={black, semithick, shorten >=-8pt},
           inner sep=0pt, label={[append after command={%
                node[text width=32mm, fill=orange!20, outer sep=0pt,%
                     at=(\tikzlastnode.#2),% position of pin
                     anchor=#1,% for node withpin text
                    ]{#3}}]center:{}}% for details see https://tex.stackexchange.com/questions/246995/
          ]#2:{}}%
    }
                    ]
\draw [thick,-latex](0,0) -- (6.2,0) node [black, xshift=.3cm, yshift=0cm] {$x$};
\draw [thick,-latex](0,0) -- (0,5) node [black, xshift=0cm, yshift=.3cm] {$u$};
\draw [ultra thick,blue] (0,2.84) --
    node [dot,aligned pin={[west]45:very very very very very very very long long long long long long long text}] + (-40:4.44cm);
\end{tikzpicture}

\end{frame}
\end{document}

这使:

在此处输入图片描述

相关内容