在椭圆体之间弯曲文本

在椭圆体之间弯曲文本

我想让一些文本与椭圆顶部或底部的中心对齐。我试过

\documentclass[border=0.5]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathtools,amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
        \draw (0,0) ellipse [x radius=3, y radius = 2];
        \draw (0,0) ellipse [red,x radius=4, y radius = 2.66];
        \draw(0,0) ++(-3.5,0)  [decorate,decoration={text along path, text={This text should be between the eppelipses in the bottom half}}] arc [start angle=-160, end angle=-10, x radius=3.5, y radius = 3];
        \draw(0,0) ++(-3.5,0)  [decorate,decoration={text along path, text= {This text should be centered and in the top half}}] arc [start angle=160, end angle=10, x radius=3.5, y radius = 4];
        \node at (0,0) {center text};
\end{tikzpicture}
\end{document}

我明白了

在此处输入图片描述

答案1

我猜你需要让弧线延伸到整个长度,同时还要考虑文本的高度。编辑:已添加text align=center,再次向 Max 表示衷心的感谢!

\documentclass[border=0.5]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathtools,amsmath}
\usepackage{tikz}

\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
        \draw (0,0) ellipse [x radius=3, y radius = 2];
        \draw (0,0) ellipse [red,x radius=4, y radius = 2.66];
        \pgfmathsetmacro{\myx}{(3.5cm+height("T")*0.5pt)*1pt/1cm}
        \pgfmathsetmacro{\myy}{(2.33cm+height("T")*0.5pt)*1pt/1cm}
        \draw [decorate,decoration={text along path,text align=center,
         text={This text should be between the ellipses in the bottom half}}] 
        ({-\myx},0) arc [start angle=-180, end angle=00, x radius=\myx, y radius = \myy];
        \pgfmathsetmacro{\myx}{(3.5cm-height("T")*0.5pt)*1pt/1cm}
        \pgfmathsetmacro{\myy}{(2.33cm-height("T")*0.5pt)*1pt/1cm}
        \draw   [decorate,decoration={text along path,text align=center,
         text= {This text
        should be centered and in the top half}}] 
         (180:{\myx} and \myy) arc [start angle=180,
        end angle=0, x radius=\myx, y radius = \myy];
        \node at (0,0) {center text};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容