5

I used pgfplotstable to read the data from a file.

The columns have fixed widths. The third column contains usual text and the lines are broken nicely. The second column contains mathematical expressions, which don't have white spaces and can be quite long and surpass the width of the column. In that case I want the expression to break and resume on the next line.

At the moment, line breaks can only occur next to some special characters (like the minus sign, see the third row), but I want it to be able to occur next to some other characters (for example, the asterisk). So, for example, the first line could break after "-V_lm/(epsilon0_const*2*pir)" and the next line could have "1[F]*1[V/m]".

Does anybody know how to accomplish this?

Also the code (which is not really relevant to the problem, but just in case) :

\begin{table}[H]
\centering
\newcolumntype{C}{>{}p{60mm}}% a centered fixed-width-column
\pgfplotstabletypeset[
    col sep=ampersand,
    columns/Name/.style={verb string type},
    columns/Expression/.style={column type=|C, verb string type},
    columns/Description/.style={column type=|C, verb string type},
    empty cells with={--}, % replace empty cells with ’--’
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule},
]{./equations.txt}
\caption{Implementation.}
\end{table}

The file I'm reading the data from:

Name&Expression&Description
normE&-V_lm/(epsilon0_const*2*pi*r)*1[F]*1[V/m]&Normal electric field (V/m)
T&T[1/K]&Temperature (K)
F&max(g_normE*1[m/V]*1e-9,1e-12)&product of local electric field strength and elementary charge (eV/nm)
  • You probably need to show an example of the math markup (without the pgfplots table which isn't directly relevant. * is by default a \mathbin so tex will break after * as it does after - but it never breaks inside {} or inside \left\right – David Carlisle May 31 '14 at 10:51
  • Oh no, perhaps that's not relevant, are you setting this as text (not math) ? – David Carlisle May 31 '14 at 10:52
  • I'm sorry, yes, the math needs to be in text format (verb string type). The math expression needs to be copyable to another program, so I want it to be right as it is in the picture, only the line breaks are problematic. – eimrek May 31 '14 at 11:05
  • It would still help to see the markup, especially if you are using verbatim as that affects how you can add linebreaks – David Carlisle May 31 '14 at 11:23
  • @DavidCarlisle I added the source text file. – eimrek May 31 '14 at 14:06
7

enter image description here

Mico's just posted a url version, but if you want to control individual characters by hand:

\documentclass{article}
\usepackage{array}
\usepackage[T1]{fontenc}
\begin{document}

\newcolumntype{C}{>{\centering\arraybackslash}p{60mm}}% a centered fixed-width-column
{\catcode`_=12
\begin{tabular}{lCC}
Name&Expression&Description\\
normE&-V_lm/(epsilon0_const*2*pi*r)*1[F]*1[V/m]&Normal electric field (V/m)\\
T&T[1/K]&Temperature (K)\\
F&max(g_normE*1[m/V]*1e-9,1e-12)&product of local electric field strength and elementary charge (eV/nm)
\end{tabular}
}

\bigskip

{\catcode`_=12
\catcode`*\active
\def*{\string*\linebreak[0]}
\begin{tabular}{lCC}
Name&Expression&Description\\
normE&-V_lm/(epsilon0_const*2*pi*r)*1[F]*1[V/m]&Normal electric field (V/m)\\
T&T[1/K]&Temperature (K)\\
F&max(g_normE*1[m/V]*1e-9,1e-12)&product of local electric field strength and elementary charge (eV/nm)
\end{tabular}
}

\end{document}
  • Thanks for the answer, I got your example to work, it's right what I wanted. But for some reason, I can't get it to work with pgfplotstable, I tried adding the \catcode*\active \def*{\string*\linebreak[0]}` before my \pgfplotstabletypeset[..], but it didn't work. I'll investigate this further... – eimrek May 31 '14 at 18:57
  • Alright, so I made a Python script to format my table data and then copied it into my latex source file. And used your solution. Tedious, but worked, so I'll accept this. – eimrek Jun 5 '14 at 22:51
5

If I understand your objective correctly, the long mathstrings must not be processed by TeX and rendered as formulas but must be rendered in pure text mode. You could try encasing the long math strings in \url{...} directives, as is done in the following example. LaTeX usually finds decent line breaks for such strings.

(I've taken the liberty of transposing your pgfplotstable setup into a more readily recognizable tabular setup for the sake of this example.)

enter image description here

\documentclass{article}
\usepackage{array,booktabs}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{6cm}"
\usepackage[hyphens]{url} % allow line breaks at hyphens
\begin{document}
\begin{table}
\centering
\begin{tabular}{@{} l *{2}{L{6cm}} @{}}
\toprule
Name &Expression&Description\\
\midrule
normE&\url{-V_lm/(epsilon0_const*2*pi*r)*1[F]*1[V/m]}
&Normal electric field (V/m)\\
T&\url{T[1/K]}&Temperature (K)\\
F&\url{max(g_normE*1[m/V]*1e-9,1e-12)}
&product of local electric field strength and elementary charge (eV/nm)\\
\bottomrule
\end{tabular}
\end{table}
\end{document} 
  • @Manuel - thanks for catching and fixing the typo – Mico May 31 '14 at 18:35
  • I just edited because it was less than a minute later than your edit. But I usually don't do that :P – Manuel May 31 '14 at 18:38
  • Interesting idea and would solve my problem, but I have no idea how to adapt this into my example. Maybe by somehow tweaking this line columns/Expression/.style={column type=|C, verb string type},? Not sure... – eimrek May 31 '14 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.