# ShareLaTeX - Text formatted as table conversion into LaTeX table

I want to convert a plain text formatted as a table into a LaTeX table. I have a routing table I wanted to include in my file but here it is:

Routing Tables: Public
Destinations : 10       Routes : 10

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

10.0.1.0/24  Direct  0    0           D   10.0.1.1        LoopBack0
10.0.1.1/32  Direct  0    0           D   127.0.0.1       LoopBack0
10.0.1.255/32  Direct  0    0           D   127.0.0.1       LoopBack0
10.0.12.0/24  Direct  0    0           D   10.0.12.1       GigabitEthernet
0/0/0


I tried manually to create a table but I have to include many like this and it would take too long, I also tried consider it as code using \begin{listing}... \end{listing} but doesn't format well either.

I was wondering if is there was any tool or suggested command.

PS: Also the last line "0/0/0" should be part of the previous one.

• May be this might help you tex.stackexchange.com/questions/165918/… ? I think you could pull the same work-around mentioned there – Raaja_is_at_topanswers.xyz Aug 6 '18 at 6:58
• there are tools but really with a any text editor it should only be a few seconds work to change each run of white space to &, add a \\  at the end of the lines and then add some \begin{tabular} markup that gives the possibility for hand tuning the layout and will give better, more understandable markup and output than an automated generation. – David Carlisle Aug 6 '18 at 8:14

If your aim is to include the output of some program and not to adapt the information, you can include it verbatim, either by copying it to the LaTeX file or by keeping it in a separate file that is included verbatim. Depending on the text width you may have to adapt the font size.

\documentclass{article}
\usepackage{verbatim}
\begin{document}

\noindent
{\footnotesize
\begin{verbatim}
Routing Tables: Public
Destinations : 10       Routes : 10

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

10.0.1.0/24  Direct  0    0           D   10.0.1.1        LoopBack0
10.0.1.1/32  Direct  0    0           D   127.0.0.1       LoopBack0
10.0.1.255/32  Direct  0    0           D   127.0.0.1       LoopBack0
10.0.12.0/24  Direct  0    0           D   10.0.12.1       GigabitEthernet 0/0/0
\end{verbatim}
}

% Alternatively, load the data from a file.

\noindent
{\footnotesize
\verbatiminput{routing.txt}
}

\end{document}


The file routing.txt contains the following lines:

Routing Tables: Public
Destinations : 10       Routes : 10

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

10.0.1.0/24  Direct  0    0           D   10.0.1.1        LoopBack0
10.0.1.1/32  Direct  0    0           D   127.0.0.1       LoopBack0
10.0.1.255/32  Direct  0    0           D   127.0.0.1       LoopBack0
10.0.12.0/24  Direct  0    0           D   10.0.12.1       GigabitEthernet 0/0/0