
저는 Windows 7 Pro에서 WinEdt 9.0, MikTex 2.9를 실행하고 있습니다.
표준 형식의 PDF 보고서를 작성 중이며 해당 형식을 따라야 합니다(예: 테이블은 색상 및 글꼴 등이 포함된 특정 형식으로 되어 있음). 명확히 말하면 테이블 레이아웃은 복잡하고 미리 정의되어 있습니다. 내가 해야 할 일은 데이터 포인트를 추가하는 것뿐입니다.
이 형식을 사용하려면 내 PC의 CSV 파일에 보관된 부동 데이터 포인트로 큰 테이블을 채워야 합니다. 이 작업을 수행하는 방법에는 여러 가지가 있는 것 같지만 어느 것이 가장 간단한지는 잘 모르겠습니다. 이상적으로는 myFile.txt를 "인덱싱"할 수 있기를 원합니다. 예: x= load(myFile.txt), val1 = x(3,17); 등
"myFile.txt"의 값을 내 변수 val1, val2, val3, val4에 어떻게 할당합니까?
내 MWE는 아래에 있습니다. 감사합니다!
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{float}
\usepackage{xspace}
\usepackage{verbatim}
\usepackage{array}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{ifthen}
%http://www.tug.org/texmf-dist/doc/latex/pgfplots/pgfplotstable.pdf
\newread\file
\openin\file=A:/myReports/latestResults/myFile.txt
\loop\unless\ifeof\file
\read\file to\fileline % Reads a line of the file into \fileline
% Do something with \fileline
\repeat
\closein\file
\begin{tabular}{|c|c|c|}
\hline
t1 & t2 & t3 \\
y1 & val1 & val4 \\
y2 & val2 & val3 \\
\hline
\end{tabular}
\end{document}
답변1
쉬운 옵션은 다음을 사용하는 것입니다 knitr
.
\documentclass[twocolumn]{article}
\usepackage{booktabs}
\parskip1em\parindent0pt
\begin{document}
The CSV file:
<<echo=F,comment=NA>>=
Val <- read.csv("values.csv",header=T)
val <- Val$Values ## just to simplify the \Sexpr
Val
@
The \LaTeX\ table:\par
\begin{tabular}{ccc}\toprule
t1 & t2 & t3 \\\midrule
y1 & \Sexpr{val[1]} & \Sexpr{val[4]} \\
y2 & \Sexpr{val[2]} & \Sexpr{val[3]} \\
\bottomrule
\end{tabular}
\end{document}