在我的文档中,我定义了一些元素它们都有一个编号(从 1 表示第一个到 n 表示最后一个)和一个级别(1、2 或 3)。
在文档的末尾,我想创建一个条形图,其值来自元素数量和级别。X 值的名称应该是设置元素的子部分的标题。
以下是一个简短的例子:
\documentclass[10pt,a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\newcounter{numOfElem}
\newcommand{\elem}[2]{
\stepcounter{numOfElem}
\begin{tabular}{|c|p{6cm}|c|}
\hline
E\thenumOfElem & #1 & #2 \\
\hline
\end{tabular}
}
\begin{document}
\section{Section 1}
First section.
\section{Section 2}
\subsection{X value 1}
This subsection title will be the first X value in the graph
\elem{First elem of level 1}{1}
\elem{Another elem of level 3}{3}
\subsection{X value 2}
This subsection's title will be the second X value in the graph.
\elem{Other elem of level 2}{2}
\elem{Other elem of level 3}{3}
\elem{Other elem of level 1}{1}
\elem{A last elem of level 1}{1}
\subsection{Other X value}
This subsection's title will be the second X value in the graph.
\elem{Other elem of level 1}{1}
\elem{Other elem of level 2}{2}
\elem{A last elem of level 3}{3}
\section{Final result}
There are \thenumOfElem~in the document.
\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={\#Elements},
symbolic x coords={X value 1, X value 2, Other X value},
xtick=data,
xticklabel style = {rotate = 90},
nodes near coords,
nodes near coords align={vertical},
]
\addplot coordinates {(X value 1,1) (X value 2,2) (Other X value,1)};
\addplot coordinates {(X value 1,0) (X value 2,1) (Other X value,1)};
\addplot coordinates {(X value 1,1) (X value 2,1) (Other X value,1)};
\end{axis}
\end{tikzpicture}
\end{document}
我需要你的帮助来定义最好的乳胶方法来做到这一点。
简而言之,我需要一个变量symbolic x coords={X value 1, X value 2, Other X value},
和\addplot coordinates {(X value 1,1) (X value 2,2) (Other X value,1)};
几行。
感谢您的帮助。