30

Is there a plug in or something that can convert Ms Word or Ms Excel tables exactly as they are (with borders etc) to Latex? I have used http://www.ctan.org/pkg/excel2latex but it removes the lines in between cells.

I also tried to use http://www.tablesgenerator.com/# but it is time consuming and I have large and complicated tables

6
  • 4
    Define 'complicated'. If it's just large, that shouldn't be a problem -- but if the tables are actually complex (tables within tables (shudder), etc.), then you won't have much luck. May 20, 2015 at 15:43
  • 2
    @user930901 See this discussion for another option tex.stackexchange.com/questions/179208/how-to-use-calc2latex. This requires you have LibreOffice installed with the calc2latex addin enabled. Again is can handle simple tables with simple formatting. May 20, 2015 at 16:37
  • by complicated I mean large and borders and lines separating each row and column and also some cells are merged May 20, 2015 at 16:55
  • 1
    Sounds simple enough for excel2latex -- have you tried it? May 20, 2015 at 17:18
  • 3
    Excel2LaTeX used to override your rules if you enabled the booktabs option. As of v3.4.0 it doesn't do this anymore. So anyone reading this in the future should give it a shot! (Disclaimer: I currently maintain Excel2LaTeX.)
    – Chel
    Aug 1, 2016 at 7:19

11 Answers 11

11

I have used the calc2latex macro in LibreOffice Calc to convert MS Excel files into LaTeX without issue. It handles borders and cell outlines fairly well.

This package, found at http://calc2latex.sourceforge.net/, is mentioned in a comment by @r-schumacher; however, it should be an official answer.

7

There's always excel2latex; I'm not sure how well it works, but it's on CTAN.

If this or some similar program doesn't work, and it is absolutely, positively not an option to recreate these tables in LaTeX, the best you'll probably be able to manage is convert them to an image and include them that way.

It seems that there are some convoluted ways to do this from within Excel (see, e.g., convert MS tables to images.

You can also simply take screenshots and get the images that way.

You can then include the resulting image in your LaTeX document in the usual way:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{table.jpg}
\end{document}

The problem with this approach is that your fonts, line thickness, and such may not match those in your tables. But that is a peril of using binary or non-transparent file formats.

1
5

To say it short: No.

A little bit longer: If you want to have good looking tables you can find hints in several books over typography (for example the german book "Lesetypografie" or "Detailtypografie", I do not have english books, sorry) that for a good typography you should use empty place and no lines. Only to mark the header and the bottom of a table you can use lines (call package booktabs for this and please read the documentation of it).

To get good tables you need a good constuction of the table. I fear in the most cases you can only get this with good old handwork ...

@Sean Allred clarified in his comment: in the absolutely general case (i.e. arbitrarily complex), conversion is not possible. However, scripts exist which try to take the most simple of these cases and create an analog for them with LaTeX. It very much depends on how complicated you made your table with a format that nobody but Microsoft really understands.

1
  • 3
    +1, but I want to clarify a bit for OP: in the absolutely general case (i.e. arbitrarily complex), conversion is not possible. However, scripts exist which try to take the most simple of these cases and create an analog for them with LaTeX. It very much depends on how complicated you made your table with a format that nobody but Microsoft really understands. May 20, 2015 at 15:43
5

For future readers: I am using a free online tool for my thesis and is working very well: Table Converter Online

2
  • Just to let everyone know, it worked perfectly for me. Thanks @ROBBAT1 Aug 16, 2022 at 5:01
  • Can you add some examples of how to use the online tool? Dec 21, 2022 at 9:56
4

I created new tool for this task. It works well with numbers on Mac, but should be able to work with excel tables. Select your table, copy it to clipboard, use tool and paste tex table.

https://github.com/helotpl/cliptable

example in action

1
  • 1
    Does not support any other formatting than bold fonts, even borders does not work for LaTex Mar 6, 2021 at 4:26
1

There is a work around using Lyx. You can insert a table of the exact number of rows and columns. Copy the table in Excel, should work in Word too. Then in the top left hand corner cell go to Edit-Paste Special-Plain Text. You can then do tidy it up, merge cells etc. If you have the Latex source window visible you can copy and paste the Latex markup into your tex file.

1

Google Sheets has an elegant solution. I know it's not MS Excel, but... we can always copy-paste Excel to Google Sheets.

  1. Install LatexKit plugin https://workspace.google.com/marketplace/app/latexkit/716178627426
  2. Select the cells you want, and then Make Tabular Make Tabular
  3. enter image description here

P.S.

  • I too wish someone developed/ported LatexKit to Excel.
  • Images are all taken from LatexKit Google marketplace
1

Googling this in 2022 helped me find https://www.latex-tables.com/, which worked perfectly for my purposes.

To create a Latex table using this tool (up to date 2022-12-20):

  • click "New"
  • select whether to upload e.g. a JSON or Excel file, or to paste table data directly from Excel
  • click "Generate" to generate the Latex code (other formats can also be selected such as HTML)
  • optionally change settings using the cogwheel (I had to check the "Don't escape Latex commands box to avoid \citet{reference} being transformed into \textbackslash citet...)
3
  • Can you add some examples of how to use the online tool?
    – Werner
    Dec 19, 2022 at 19:33
  • @Werner sure. Don't know why my answer gets delete votes and downvoted when similar answers have not been questioned... but I digress. Dec 20, 2022 at 9:59
  • 1
    This may happen when the answer just provides an external link and comes from a low-rep user. Community members may think it's click-bait or something managed by the user without disclosing it. Such answers are better-suited as comments in general. However, a complete layout of the process and screenshots always helps boost the value so visitors can immediately see whether the source link can help them or not, rather than bouncing there and trying to figure it out themselves.
    – Werner
    Dec 20, 2022 at 18:30
0

On Mac OS X I suggest the following solution which can similarly work on other OS. The solution allows to work with light-vectorial images.

  1. Export your sheet as a .pdf file
  2. Open it with preview app end use the selection tool to select the interesting part of the table.
  3. Copy it (cmd+c) and open a new preview window (cmd+n)
  4. Save the selected table as my_table.pdf
  5. Import my_table.pdf by

    \documentclass{article} 
    \usepackage{graphicx}
    \begin{document}
    \includegraphics{my_table.pdf}
    \end{document}
    
3
  • 3
    But the fonts could be different from the rest of the LaTeX document...
    – CarLaTeX
    Apr 19, 2017 at 8:49
  • You have to choose the font properly before to export.
    – Colo
    Apr 19, 2017 at 8:51
  • 1
    @Colo That's not always as simple as it sounds. As it is currently written it is a very specific answer for a very general problem. Probably you should try to elaborate on some solutions to common issues with that solution.
    – TeXnician
    Apr 19, 2017 at 9:10
0

Inspiring by @Colo.

If you export the table as PDF file, and - after - process it with Inskcape, you save it as PDF, Inskcape say you if you would like a single PDF or a PDF + LaTeX format, where all the fonts are replaced by LaTeX and... are the same of your document.

0

One idea to reduce the workload could be to import the Excel file into R, then export it with " & " as separator and copying the final result from the text file into Latex:

library(readxl)

yourexcel <- read_excel("yourexcel.xlsx")

write.table(yourexcel, file = "export.txt", sep = " & ", row.names = FALSE, quote = FALSE)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .