2

I'm having problems getting the pgfplotstable to compile because of issues with file path names containing spaces. I have read a bunch of other posts that say to just put quotes around things but none of that works for me. Also, I cannot change any of the path names because the files are edited by multiple people and I have about 5GB of data that is all file path dependent so it isn't really an option to just remove the spaces in the filenames.

Here is a MWE which works when the .tex file is placed in the same folder as the .txt file. The path formats that I have tried are shown on the filename line.

\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}

Is there any way that I can get this to work without having to manually remove the spaces from my files? I'm on a Windows machine.

This is the contents of the txt file.

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

EDIT: Added other cases that I tried and failed.

  • Does this help? http://tex.stackexchange.com/questions/191930/spaces-in-files-names-in-input-or-includegraphics. Essentially, delimit filenames in double-quote " to allow spaces in names. – Steven B. Segletes Apr 12 '16 at 18:36
  • @StevenB.Segletes That was one of the things that I tried and doesn't work. Not sure why but it doesn't. Says that it can't open the file. – Kyle Jones Apr 12 '16 at 18:39
  • Very strange. It works for \includegraphics even for files in other directories. To borrow code from the cited answer, \includegraphics[width=2in]{"../Other Directory Repin Painting"} does work. – Steven B. Segletes Apr 12 '16 at 18:40
  • Enclose the complete filename with ", including the ../../ – Steven B. Segletes Apr 12 '16 at 18:41
  • 1
    @StevenB.Segletes If you look at my MWE that was the first thing I tried. I have even tried putting in the absolute directory (including the drive letter, etc.) and that didn't work either. – Kyle Jones Apr 12 '16 at 18:46
  • Sorry, didn't see that invocation. – Steven B. Segletes Apr 12 '16 at 18:47
  • My last contact with Windows was many years ago, when symbolic and hard links where only in *nix OS, but what about some like mklink /J <link> <target> ? – Fran Apr 12 '16 at 19:44

1 Answers1

3

Inside the table, add \protect to \pgfplotstabletypeset.

I first tested that \pgfplotstabletypeset worked with filenames-with-spaces not inside a table, and that worked OK. Thus, I concluded the issue was with the use of table and not intrinsically with \pgfplotstabletypeset. The use of \protect immediately fixed the problem.

\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}

enter image description here

  • This corrected the problem. I guess my next question would be what is the \protect macro and why is it that this fixed the issue? – Kyle Jones Apr 12 '16 at 20:10
  • 1
    @KyleJones It is not the easiest concept (I don't fully understand all the ins and outs myself), but is addressed here: http://tex.stackexchange.com/questions/4736/what-is-the-difference-between-fragile-and-robust-commands. There are "fragile" and "robust" commands. The macro \protect allows the subsequent macro to be skipped over during the next call for argument expansion, which can keep a fragile macro from getting scrogged. – Steven B. Segletes Apr 12 '16 at 23:29
  • @StevenB.Selgetes Thanks for the info. I'll do a little reading about it. – Kyle Jones Apr 13 '16 at 14:01