由于文件路径名包含空格,我在编译时遇到了问题pgfplotstable
。我读过很多其他帖子,它们说只要在内容周围加上引号,但这些对我都不起作用。此外,我无法更改任何路径名,因为这些文件由多人编辑,而且我有大约 5GB 的数据,它们全都与文件路径相关,因此仅仅删除文件名中的空格并不是一个真正的选择。
.tex
这是当文件与文件放在同一文件夹中时工作的 MWE .txt
。我尝试过的路径格式显示在文件名行上。
\documentclass[letter]{article}
\usepackage{mathpazo} % Change math and rm fonts to palatino
\usepackage{tikz} % For drawing figures
\usetikzlibrary{calc} % For making complex coordinate calculations
\usepackage{pgfplots} % For generating plots
\pgfplotsset{compat=newest} % Use newest version of pgfplots
\usepackage{pgfplotstable} % For generating text file based tables
\usepackage{booktabs} % For using lines in tables
\begin{document}
See Table \ref{tab:inflowlosses}.
\begin{table}
\centering
\caption{Pressure drop and loss coefficient across the inlet flow conditioning for each test case.}
\pgfplotstabletypeset[col sep=comma,columns={Name,P,uP,K,uK},
columns/Name/.style = {string type,column type=c,column name={}},
columns/P/.style = {fixed,zerofill,precision=4,column type=r,column name={},column type/.add={}{@{$\pm$}}},
columns/uP/.style = {fixed,zerofill,precision=4,column type=l,column name={}},
columns/K/.style = {fixed,zerofill,precision=0,column type=r,column name={},column type/.add={}{@{$\pm$}}},
columns/uK/.style = {fixed,zerofill,precision=0,column type=l,column name={}},
every head row/.style = {before row={\\ \toprule \multicolumn{1}{c}{Case Name} & \multicolumn{2}{c}{$\Delta P$, [Pa]} & \multicolumn{2}{c}{$K$}\\}, output empty row, after row=\midrule},
every last row/.style = {after row=\toprule}
]
{LossesTable.txt}
%{"../../Fuel Rods NEUP Project/Codes/Flow Conditioning Pressure Drop/LossesTable.txt"} %fails
%{../../"Fuel Rods NEUP Project"/Codes/"Flow Conditioning Pressure Drop"/LossesTable.txt} %fails
%{../../"Fuel Rods NEUP Project/Codes/Flow Conditioning Pressure Drop/LossesTable.txt"} %fails
%{../../Fuel\ Rods\ NEUP\ Project/Codes/Flow\ Conditioning\ Pressure\ Drop/LossesTable.txt} %fails
%{../../Fuel~Rods~NEUP~Project/Codes/Flow~Conditioning~Pressure~Drop/LossesTable.txt} %fails
%{"D:/Google Drive/Dropbox/Fuel Rods NEUP Project/Codes/Flow Conditioning Pressure Drop/LossesTable.txt"} %fails
%{D:/"Google Drive"/Dropbox/"Fuel Rods NEUP Project"/Codes/"Flow Conditioning Pressure Drop"/LossesTable.txt} %fails
\label{tab:inflowlosses}
\end{table}
\end{document}
有什么方法可以让它工作,而不必手动从我的文件中删除空格?我在 Windows 机器上。
这是txt文件的内容。
Name,P,uP,K,uK
Forced,9.217715e-01,4.432833e-02,5.314139e+02,2.664182e+02
Mixed400,7.999960e-01,3.571976e-02,4.670493e+02,2.282758e+02
Mixed700,8.037027e-01,4.365411e-02,4.669018e+02,2.343152e+02
Natural400,1.226934e-01,2.196708e-02,3.265355e+03,1.703273e+03
Natural700,1.531152e-01,2.102355e-02,2.400092e+03,1.163889e+03
编辑:添加了我尝试过但失败的其他案例。
答案1
在里面table
,添加\protect
到\pgfplotstabletypeset
。
我首先测试了 是否能\pgfplotstabletypeset
与不在 内的带空格的文件名一起使用table
,并且运行正常。因此,我得出结论,问题出在使用table
而不是 的本质\pgfplotstabletypeset
。使用\protect
立即解决了问题。
\documentclass[letter]{article}
\usepackage{mathpazo} % Change math and rm fonts to palatino
\usepackage{tikz} % For drawing figures
\usetikzlibrary{calc} % For making complex coordinate calculations
\usepackage{pgfplots} % For generating plots
\pgfplotsset{compat=newest} % Use newest version of pgfplots
\usepackage{pgfplotstable} % For generating text file based tables
\usepackage{booktabs} % For using lines in tables
\usepackage{filecontents}
\begin{filecontents*}{"Losses Table.txt"}
Name,P,uP,K,uK
Forced,9.217715e-01,4.432833e-02,5.314139e+02,2.664182e+02
Mixed400,7.999960e-01,3.571976e-02,4.670493e+02,2.282758e+02
Mixed700,8.037027e-01,4.365411e-02,4.669018e+02,2.343152e+02
Natural400,1.226934e-01,2.196708e-02,3.265355e+03,1.703273e+03
Natural700,1.531152e-01,2.102355e-02,2.400092e+03,1.163889e+03
\end{filecontents*}
\begin{document}
See Table \ref{tab:inflowlosses}.
\begin{table}
\centering
\caption{Pressure drop and loss coefficient across the inlet flow conditioning for each test case.}
\protect\pgfplotstabletypeset[col sep=comma,columns={Name,P,uP,K,uK},
columns/Name/.style = {string type,column type=c,column name={}},
columns/P/.style = {fixed,zerofill,precision=4,column type=r,column name={},column type/.add={}{@{$\pm$}}},
columns/uP/.style = {fixed,zerofill,precision=4,column type=l,column name={}},
columns/K/.style = {fixed,zerofill,precision=0,column type=r,column name={},column type/.add={}{@{$\pm$}}},
columns/uK/.style = {fixed,zerofill,precision=0,column type=l,column name={}},
every head row/.style = {before row={\\ \toprule \multicolumn{1}{c}{Case Name} & \multicolumn{2}{c}{$\Delta P$, [Pa]} & \multicolumn{2}{c}{$K$}\\}, output empty row, after row=\midrule},
every last row/.style = {after row=\toprule}
]
{../../Losses Table.txt}
%{"../../Fuel Rods NEUP Project/Codes/Flow Conditioning Pressure Drop/LossesTable.txt"} %fails
%{../../"Fuel Rods NEUP Project"/Codes/"Flow Conditioning Pressure Drop"/LossesTable.txt} %fails
%{../../"Fuel Rods NEUP Project/Codes/Flow Conditioning Pressure Drop/LossesTable.txt"} %fails
%{../../Fuel\ Rods\ NEUP\ Project/Codes/Flow\ Conditioning\ Pressure\ Drop/LossesTable.txt} %fails
%{../../Fuel~Rods~NEUP~Project/Codes/Flow~Conditioning~Pressure~Drop/LossesTable.txt} %fails
%{"D:/Google Drive/Dropbox/Fuel Rods NEUP Project/Codes/Flow Conditioning Pressure Drop/LossesTable.txt"} %fails
%{D:/"Google Drive"/Dropbox/"Fuel Rods NEUP Project"/Codes/"Flow Conditioning Pressure Drop"/LossesTable.txt} %fails
\label{tab:inflowlosses}
\end{table}
\end{document}