
我的目標是使用乳膠創建一個測量協議。由於它將被軟體用來創建協議,因此嘗試實現一些自動化。意思是,我希望 LaTex 根據巢狀清單中的值建立文件的各個部分。因此,此列表儲存值列表,這些值將在要建立的單一部分中使用。
這是迄今為止我的程式碼的摘錄:
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{svg}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{xstring}
\usepackage{caption}
\usepackage{dashrule}
\usepackage{pgfplots}
\usepackage{float}
\usepackage{nicefrac}
\usepackage{float}
\usepackage{lscape}
\usepackage{xcolor}
\usepackage[export]{adjustbox}
\usepackage{colortbl}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage[format=plain]{caption}
\usepackage{xparse}
\usepackage{nicefrac}
\usepackage[export]{adjustbox}
\usepackage{graphicx}
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=3.8cm]{geometry}
\renewcommand{\figurename}{Bild}
\renewcommand{\tablename}{Tabelle}
\definecolor{ArrangementClassA}{HTML}{c000c0}
\definecolor{ArrangementClassB}{HTML}{00c000}
\definecolor{ArrangementClassC}{HTML}{a52a2a}
\definecolor{ArrangementClassD}{HTML}{00c0c0}
\definecolor{ArrangementClassE}{HTML}{0000a0}
\ExplSyntaxOn
\NewDocumentCommand \CountItems { m } {
\clist_count:N #1
}
\NewDocumentCommand \CountInlineItems { m } {
\clist_count:n {#1}
}
\ExplSyntaxOff
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document variables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\ImgDirPathArrangementClasses}{protocol_images/flake/arrangement_classes/}
\newcommand{\ImgDirPathSizeClasses}{protocol_images/flake/size_classes/}
\newcommand{\ImgCalibration}{0.785}
% Nested lists to store images and measurement results
\ExplSyntaxOn
\NewDocumentCommand{\DeclareListOfValues}{ m m }
{
\clist_gclear_new:c {g_list_of_values_#1_clist}
\clist_gset:cn {g_list_of_values_#1_clist} {#2}
}
\NewExpandableDocumentCommand{\GetValueFromList}{ m o m }
{
\IfValueTF { #2 }
{
\exp_args:Ne \clist_item:nn { \clist_item:cn {g_list_of_values_#1_clist} {#3} } { #2 }
}
{
\clist_item:cn {g_list_of_values_#1_clist} {#3}
}
}
\ExplSyntaxOff
%List structure: {TotResClassA,TotResClassB,TotResClassC,TotResClassD,TotResClassE}
\DeclareListOfValues{GraphiteArrangementClassesTotalRes}{70.2,29.8,0,0,0}
%List structure: {{ImgName,ResClassA,ResClassB,ResClassC,ResClassD,ResClassE},{...},{...},...}
\DeclareListOfValues{GraphiteArrangementClasses}{
{14-1-11,73.6,26.4,0,0,0},
{15-1-4,72.7,27.3,0,0,0},
{15-1-6,67.7, 32.3,0,0,0},
{16-1-10,75.6, 24.4,0,0,0},
{1562-3-6,68.7,31.3,0,0,0},
{1562-3-16,71.6,28.4,0,0,0},
{1563-3-8,85.9,14.1,0,0,0},
{1563-3-13,71.8,28.2,0,0,0},
{1564-2-7,58.1,41.9,0,0,0},
{1564-3-14,56.2,43.8,0,0,0}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% End Document variables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Auswertung nach Graphitanordnung gemäß DIN EN ISO 945}
\subsection{Gesamtauswertung}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[
/pgf/number format/1000 sep={},
width=.7\linewidth,
height=1.4in,
enlarge y limits={upper, value=0.2},
scale only axis,
clip=false,
separate axis lines,
axis on top,
xmin=0,
xmax=6,
xtick={1,2,3,4,5},
x tick style={draw=none},
xticklabels={A,B,C,D,E},
ytick={0,20,40,60,80,100},
ymin=0,
ymax=100,
ylabel={Häufigkeit $[\%]$},
xlabel={Anordnungsklassen},
every axis plot/.append style={
ybar,
bar width=32.0,
bar shift=0pt,
fill
},
title=\textbf{Graphitanordnung - Gesamtergebnis},
nodes near coords
]
\addplot[fill=ArrangementClassA, draw=ArrangementClassA]coordinates {(1,\GetValueFromList{GraphiteArrangementClassesTotalRes}{1})};
\addplot[fill=ArrangementClassB, draw=ArrangementClassB]coordinates{(2,\GetValueFromList{GraphiteArrangementClassesTotalRes}{2})};
\addplot[fill=ArrangementClassC, draw=ArrangementClassC]coordinates{(3,\GetValueFromList{GraphiteArrangementClassesTotalRes}{3})};
\addplot[fill=ArrangementClassD, draw=ArrangementClassD]coordinates{(4,\GetValueFromList{GraphiteArrangementClassesTotalRes}{4})};
\addplot[fill=ArrangementClassE, draw=ArrangementClassE]coordinates{(5,\GetValueFromList{GraphiteArrangementClassesTotalRes}{5})};
\end{axis}
\end{tikzpicture}
\end{figure}
\subsection{Einzelbildauswertungen}
% HOW TO GET VALUES FROM THE LIST - EXAMPLE
% \GetValueFromList{GraphiteArrangementClasses}{1}\\ % 14-1-11,73.6,26.4,0,0,0
% \GetValueFromList{GraphiteArrangementClasses}[1]{1}\\ % 14-1-11
% \GetValueFromList{GraphiteArrangementClasses}[2]{1}\\ % 73.6
% \GetValueFromList{GraphiteArrangementClasses}[3]{1}\\ % 26.4
% \GetValueFromList{GraphiteArrangementClasses}[4]{1}\\ % 0
% \GetValueFromList{GraphiteArrangementClasses}[5]{1}\\ % 0
% \GetValueFromList{GraphiteArrangementClasses}[6]{1}\\ % 0
% Concatenating the image path
\def\ImgPath{\ImgDirPathArrangementClasses}
\global\edef\ImgPath{\ImgPath\GetValueFromList{GraphiteArrangementClasses}[1]{1}}
\begin{minipage}[t]{0.6\linewidth}\vspace{0pt}
\begin{figure}[H]
\boxed{\includegraphics[width=\linewidth]{\ImgPath}}
\caption{\GetValueFromList{GraphiteArrangementClasses}[1]{1}}
\end{figure}
\end{minipage}~~~
\begin{minipage}[t]{0.35\linewidth}\vspace{0pt}
\begin{figure}[H]
\begin{tikzpicture}
\begin{axis}[
/pgf/number format/1000 sep={},
width=0.9\linewidth,
height=1.0in,
enlarge y limits={upper, value=0.2},
scale only axis,
clip=false,
separate axis lines,
axis on top,
xmin=0,
xmax=6,
xtick={1,2,3,4,5},
x tick style={draw=none},
xticklabels={A,B,C,D,E},
ytick={0,20,40,60,80,100},
ymin=0,
ymax=100,
xlabel={Anordnungsklassen},
every axis plot/.append style={
ybar,
bar width=12.0,
bar shift=0pt,
fill
},
title=\textbf{Graphitanordnung - Einzelbild},
nodes near coords,
every node near coord/.append style={rotate=90, anchor=west}
]
\addplot[fill=ArrangementClassA, draw=ArrangementClassA]coordinates {(1,\GetValueFromList{GraphiteArrangementClasses}[2]{1})};
\addplot[fill=ArrangementClassB, draw=ArrangementClassB]coordinates{(2,\GetValueFromList{GraphiteArrangementClasses}[3]{1})};
\addplot[fill=ArrangementClassC, draw=ArrangementClassC]coordinates{(3,\GetValueFromList{GraphiteArrangementClasses}[4]{1})};
\addplot[fill=ArrangementClassD, draw=ArrangementClassD]coordinates{(4,\GetValueFromList{GraphiteArrangementClasses}[5]{1})};
\addplot[fill=ArrangementClassE, draw=ArrangementClassE]coordinates{(5,\GetValueFromList{GraphiteArrangementClasses}[6]{1})};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{minipage}
\end{document}
我現在想做的是為每個子清單自動建立小節 (Einzelbildauswertungen)石墨編排類不幸的是,到目前為止我無法使其正常工作,因為作為 \foreach 中的參數的列表不起作用。
非常感謝解決此問題的任何幫助!
答案1
你可以只使用常規的 TeX 循環:
\documentclass[10pt,a4paper]{article}
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=3.8cm]{geometry}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{float}
\renewcommand{\figurename}{Bild}
\renewcommand{\tablename}{Tabelle}
\definecolor{ArrangementClassA}{HTML}{c000c0}
\definecolor{ArrangementClassB}{HTML}{00c000}
\definecolor{ArrangementClassC}{HTML}{a52a2a}
\definecolor{ArrangementClassD}{HTML}{00c0c0}
\definecolor{ArrangementClassE}{HTML}{0000a0}
\ExplSyntaxOn
\NewDocumentCommand \CountItems { m } {
\clist_count:N #1
}
\NewDocumentCommand \CountInlineItems { m } {
\clist_count:n {#1}
}
\ExplSyntaxOff
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document variables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\ImgDirPathArrangementClasses}{protocol_images/flake/arrangement_classes/}
\newcommand{\ImgDirPathSizeClasses}{protocol_images/flake/size_classes/}
\newcommand{\ImgCalibration}{0.785}
% Nested lists to store images and measurement results
\ExplSyntaxOn
\NewDocumentCommand{\DeclareListOfValues}{ m m }
{
\clist_gclear_new:c {g_mahakala_list_of_values_#1_clist}
\clist_gset:cn {g_mahakala_list_of_values_#1_clist} {#2}
}
\NewExpandableDocumentCommand{\GetValueFromList}{ m o m }
{
\IfValueTF { #2 }
{
\exp_args:Ne \clist_item:nn { \clist_item:cn {g_mahakala_list_of_values_#1_clist} {#3} } { #2 }
}
{
\clist_item:cn {g_mahakala_list_of_values_#1_clist} {#3}
}
}
\ExplSyntaxOff
%List structure: {TotResClassA,TotResClassB,TotResClassC,TotResClassD,TotResClassE}
\DeclareListOfValues{GraphiteArrangementClassesTotalRes}{70.2,29.8,0,0,0}
%List structure: {{ImgName,ResClassA,ResClassB,ResClassC,ResClassD,ResClassE},{...},{...},...}
\DeclareListOfValues{GraphiteArrangementClasses}{
{14-1-11,73.6,26.4,0,0,0},
{15-1-4,72.7,27.3,0,0,0},
{15-1-6,67.7, 32.3,0,0,0},
{16-1-10,75.6, 24.4,0,0,0},
{1562-3-6,68.7,31.3,0,0,0},
{1562-3-16,71.6,28.4,0,0,0},
{1563-3-8,85.9,14.1,0,0,0},
{1563-3-13,71.8,28.2,0,0,0},
{1564-2-7,58.1,41.9,0,0,0},
{1564-3-14,56.2,43.8,0,0,0}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% End Document variables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Auswertung nach Graphitanordnung gemäß DIN EN ISO 945}
\subsection{Gesamtauswertung}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[
/pgf/number format/1000 sep={},
width=.7\linewidth,
height=1.4in,
enlarge y limits={upper, value=0.2},
scale only axis,
clip=false,
separate axis lines,
axis on top,
xmin=0,
xmax=6,
xtick={1,2,3,4,5},
x tick style={draw=none},
xticklabels={A,B,C,D,E},
ytick={0,20,40,60,80,100},
ymin=0,
ymax=100,
ylabel={Häufigkeit $[\%]$},
xlabel={Anordnungsklassen},
every axis plot/.append style={
ybar,
bar width=32.0pt,
bar shift=0pt,
fill
},
title=\textbf{Graphitanordnung - Gesamtergebnis},
nodes near coords
]
\addplot[fill=ArrangementClassA, draw=ArrangementClassA] coordinates {(1,\GetValueFromList{GraphiteArrangementClassesTotalRes}{1})};
\addplot[fill=ArrangementClassB, draw=ArrangementClassB] coordinates {(2,\GetValueFromList{GraphiteArrangementClassesTotalRes}{2})};
\addplot[fill=ArrangementClassC, draw=ArrangementClassC] coordinates {(3,\GetValueFromList{GraphiteArrangementClassesTotalRes}{3})};
\addplot[fill=ArrangementClassD, draw=ArrangementClassD] coordinates {(4,\GetValueFromList{GraphiteArrangementClassesTotalRes}{4})};
\addplot[fill=ArrangementClassE, draw=ArrangementClassE] coordinates {(5,\GetValueFromList{GraphiteArrangementClassesTotalRes}{5})};
\end{axis}
\end{tikzpicture}
\end{figure}
\newcounter{iterationindex}
\loop
\stepcounter{iterationindex}
\subsection{Einzelbildauswertungen}
% HOW TO GET VALUES FROM THE LIST - EXAMPLE
% \GetValueFromList{GraphiteArrangementClasses}{1}\\ % 14-1-11,73.6,26.4,0,0,0
% \GetValueFromList{GraphiteArrangementClasses}[1]{1}\\ % 14-1-11
% \GetValueFromList{GraphiteArrangementClasses}[2]{1}\\ % 73.6
% \GetValueFromList{GraphiteArrangementClasses}[3]{1}\\ % 26.4
% \GetValueFromList{GraphiteArrangementClasses}[4]{1}\\ % 0
% \GetValueFromList{GraphiteArrangementClasses}[5]{1}\\ % 0
% \GetValueFromList{GraphiteArrangementClasses}[6]{1}\\ % 0
% Concatenating the image path
\def\ImgPath{\ImgDirPathArrangementClasses}
\global\edef\ImgPath{\ImgPath\GetValueFromList{GraphiteArrangementClasses}[1]{\theiterationindex}}
\begin{minipage}[t]{0.6\linewidth}\vspace{0pt}
\begin{figure}[H]
%\boxed{\includegraphics[width=\linewidth]{\ImgPath}}
\boxed{\includegraphics[width=\linewidth, height=4cm]{example-image-a}}
\caption{\GetValueFromList{GraphiteArrangementClasses}[1]{\theiterationindex}}
\end{figure}
\end{minipage}~~~
\begin{minipage}[t]{0.35\linewidth}\vspace{0pt}
\begin{figure}[H]
\begin{tikzpicture}
\pgfmathtruncatemacro{\currentindex}{\theiterationindex}
\begin{axis}[
/pgf/number format/1000 sep={},
width=0.9\linewidth,
height=1.0in,
enlarge y limits={upper, value=0.2},
scale only axis,
clip=false,
separate axis lines,
axis on top,
xmin=0,
xmax=6,
xtick={1,2,3,4,5},
x tick style={draw=none},
xticklabels={A,B,C,D,E},
ytick={0,20,40,60,80,100},
ymin=0,
ymax=100,
xlabel={Anordnungsklassen},
every axis plot/.append style={
ybar,
bar width=12.0pt,
bar shift=0pt,
fill
},
title=\textbf{Graphitanordnung - Einzelbild},
nodes near coords,
every node near coord/.append style={rotate=90, anchor=west}
]
\addplot[fill=ArrangementClassA, draw=ArrangementClassA] coordinates {(1,\GetValueFromList{GraphiteArrangementClasses}[2]{\theiterationindex})};
\addplot[fill=ArrangementClassB, draw=ArrangementClassB] coordinates {(2,\GetValueFromList{GraphiteArrangementClasses}[3]{\theiterationindex})};
\addplot[fill=ArrangementClassC, draw=ArrangementClassC] coordinates {(3,\GetValueFromList{GraphiteArrangementClasses}[4]{\theiterationindex})};
\addplot[fill=ArrangementClassD, draw=ArrangementClassD] coordinates {(4,\GetValueFromList{GraphiteArrangementClasses}[5]{\theiterationindex})};
\addplot[fill=ArrangementClassE, draw=ArrangementClassE] coordinates {(5,\GetValueFromList{GraphiteArrangementClasses}[6]{\theiterationindex})};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{minipage}
\ifnum\theiterationindex<10\repeat
\end{document}
一些注意事項:
- 您不應該在序言中多次載入包,因為可能會導致錯誤並減慢編譯過程。
bar width
需要一個維度,至少在目前的 PGFplots 版本中是如此。我添加pt
到給定的值。- 由於我無法存取圖片,因此我將
\boxed{\includegraphics[width=\linewidth]{\ImgPath}}
您的代碼替換為\boxed{\includegraphics[width=\linewidth, height=4cm]{example-image-a}}
.