增加 pgfplots 创建的线的长度

增加 pgfplots 创建的线的长度

我有一个命令可以在文本中画一些线条:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
 \begin{document}

\scalebox{0}{%
\begin{tikzpicture}
    \begin{axis}[hide axis]
        \addplot [
        color=orange,
        solid,
        line width=1.3pt,
        forget plot
        ]
        (0,0);\label{oranged}
        \addplot [
        color=red!30.6!green!0!blue!55.7!,
        densely dashed,
        line width=1.7pt,
        forget plot
        ]
        (0,0);\label{purpled}
        \addplot [
        color=green,
        dash pattern={on 10pt off 2pt},
        line width=1.6pt,
        forget plot
        ]
        (0,0);\label{greened}
    \end{axis}
  \end{tikzpicture}%
}%


 I have \ref{purpled} and \ref{oranged}  and \ref{greened}.


 \end{document}

此命令创建具有特殊长度的行。我做了任何事来增加长度尽管我没有成功,但有人知道我们如何实现这个目标。

答案1

我不确定我是否完全理解您想要做什么,但最好直接使用它tikz来绘制,而不是使用pgfplots

在下面的代码中,\DrawLine宏将使用给定的绘制参数绘制一条给定长度的线。我曾经\DrawLine定义\Purpled\Greened\Oranged产生下面的第二行:

在此处输入图片描述

代码:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\newcommand*{\DrawLine}[2][]{%
    \tikz [baseline] \draw [#1] (0,0.5ex) -- ++(#2,0);%
}
\newcommand*{\Purpled}[1]{%
    \DrawLine[
        draw=red!30.6!green!0!blue!55.7!, 
        dash pattern={on 10pt off 2pt}, 
        densely dashed,
        line width=1.6pt,
    ]{#1}%
}
\newcommand*{\Greened}[1]{%
    \DrawLine[
        draw=green,
        dash pattern={on 10pt off 2pt},
        line width=1.6pt,
    ]{#1}%
}
\newcommand*{\Oranged}[1]{%
    \DrawLine[
        draw=orange,
        solid,
        line width=1.3pt,
    ]{#1}%
}


\begin{document}
\scalebox{0}{%
\begin{tikzpicture}
    \begin{axis}[hide axis]
        \addplot [
        color=orange,
        solid,
        line width=1.3pt,
        forget plot
        ]
        (0,0);\label{oranged}
        \addplot [
        color=red!30.6!green!0!blue!55.7!,
        densely dashed,
        line width=1.7pt,
        forget plot
        ]
        (0,0);\label{purpled}
        \addplot [
        color=green,
        dash pattern={on 10pt off 2pt},
        line width=1.6pt,
        forget plot
        ]
        (0,0);\label{greened}
    \end{axis}
  \end{tikzpicture}%
}%


 I have \ref{purpled} and \ref{oranged}  and \ref{greened}.

 I have \Purpled{0.65cm} and \Oranged{1.0cm}  and \Greened{1.0cm}.

\end{document}

相关内容