sqlformattinglatex

How to make a SQL table look like it comes from the terminal


I have a SQL table that comes from the terminal, and I would like to be able to replicate it "as is" in a LaTeX report. It would help the reader see more clearly and do copy-paste easier for them as well. The table can look like that :

+-----------+----------+------+-----+---------+-------+
| Field     | Type     | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+-------+
| Name      | char(16) | NO   |     | NULL    |       |
| RA        | float    | NO   |     | NULL    |       |
| DE        | float    | NO   |     | NULL    |       |
+-----------+----------+------+-----+---------+-------+

And would I ideally look like that : SQL table in LaTeX (goal)


Solution

  • You could include the table as verbatim material:

    \documentclass{article}
    
    \begin{document}
    
    \begin{verbatim}
    +-----------+----------+------+-----+---------+-------+
    | Field     | Type     | Null | Key | Default | Extra |
    +-----------+----------+------+-----+---------+-------+
    | Name      | char(16) | NO   |     | NULL    |       |
    | RA        | float    | NO   |     | NULL    |       |
    | DE        | float    | NO   |     | NULL    |       |
    +-----------+----------+------+-----+---------+-------+
    \end{verbatim}
    
    \end{document}
    

    enter image description here