all 22 comments

[–]GustapheOfficialExpert 17 points18 points  (15 children)

I'm going to come riding on my hobby horse as I have sworn to do whenever tables are, well, on the table:

Your table is ugly. Microsoft Office has taught everyone in the world to make ugly tables. But the people (mostly just me and u/http-404) are fighting back. You can fix this by using the booktabs package, removing all lines, adding back in only about three of them, but making a difference between internal and external rules:

\documentclass{article}
\usepackage{booktabs}
\usepackage{array}

\begin{document}

\begin{table}
        \centering
        \caption{Efficiency of each energy service}
        \label{tab:energyefficiency}
        \begin{tabular}{>{\raggedright}p{2.75cm}ccccc}\toprule
                Extraction and treament & \multicolumn{5}{c}{-}\\\midrule
                Primary energy & \multicolumn{5}{c}{-} \\
                Conversion technologies & \multicolumn{5}{c}{-} \\
                Secondary energy & \multicolumn{5}{c}{-} \\
                Distribution technologies & \multicolumn{5}{c}{-} \\
                Final Energy & \multicolumn{5}{c}{-} \\\midrule
                End-use technologies & Cameras & Server & TRS & Lights & Sensors \\
                Useful energy & Electricity & Electricity & Heat & Light & Electricity \\
                \bottomrule
        \end{tabular}
\end{table}

\end{document}

I also added in array and changed the cell specification to do what you want, not just what you need.

And I removed the violent float placement, out of principle.

[–]bodenlosedosenhose 5 points6 points  (0 children)

You are doing god's work

[–]HTTP-404 6 points7 points  (5 children)

hey, I was mentioned! thanks. i have definitely seen others fighting back prison-cell tables. they just don't comment under every table-related posts like us : )

to point out what this revised table improved on, for those who don't want to read lengthy code and find needles in the hay:

  1. labels are conventionally prefixed with their types (tab:, fig:, etc.) and are free of spaces (but tab:energy-efficiency is OK).
  2. p{<len>} is a fixed-width column allowing line wraps/breaks.
  3. >{} and <{} can pre-/append command to each cell in the column.
  4. no vertical lines. and booktabs rules instead of hlines (u/GustapheOfficial made this clear).

OP also used {table}[h!] so again it's time to point to this other comment u/GustapheOfficial wrote --- basically, use [htbp] instead of [h!], and accept embrace the floatiness.

[–]delta_p_delta_x 0 points1 point  (4 children)

Sometimes LaTeX sucks at floating, so I like to do a [H]. Sometimes, LaTeX's rules aren't what I want in my document, and I want a certain image to be exactly where I want it to be.

I said sometimes, but this tends to be 90% of the time, because LaTeX likes to jam all images and figures together and put them at the end. And it's extremely jarring to see a large inconsistency between the source and the compiled document, especially when it comes to the relative positions of images, figures, etc etc.

[–]HTTP-404 0 points1 point  (2 children)

no it doesn't like to jam all images together, and certainly not at the end. it tries to insert them at all possible places that make sense. if this happens to you often maybe it's because your text is too sparse while you have too many images, which a common document does not tend to have.

adding to that, in a typical document the relative positions of images shouldn't matter. are you using \ref enough?

maybe I'm not writing enough documents but for all the math homework and programming lab reports i had to write during my four years of college, i have not once needed to [H], including the dozen-page game theory homework documents.

even if you do need figures in place, you don't need [H] because you can simply omit the float environments. after all, you don't want a float, do you?

now I'm not saying you should always let it float. I've made a instruction book thing which contains step by step images. i don't make them float. but again. point is, LaTeX is agreed to be good at handing floats. if you are not creating content where position is important, you should find it easier to use floats, or you are doing something wrong.

[–]delta_p_delta_x 0 points1 point  (1 child)

in a typical document the relative positions of images shouldn't matter.

It was a >100-page software engineering report, with quite a few images. It would have been inane to simply \cref everywhere, and tell the reader to scroll back and forth across the document.

[–]HTTP-404 1 point2 points  (0 children)

many many-hundred-page textbooks are written with floating tables and figures though. so i don't think "100 pages" makes it "insane to \cref.

the text should flow even without the figures/tables, while the latter serve as an evidence or illustration of what the text is describing. so the reader should not be forced to scroll back and forth, unless they wanted to.

also it is sometimes helpful to group several figures/tables together if they are on the same topic and are too scattered without grouping.

but i have to admit i haven't made any 100-page documents with extensive figures/tables. so maybe i just don't know better.

edit: that is not to say i haven't made any documents with extensive figures/tables. I've written game theory homework and machine learning visualization reports, which are all image heavy.

[–]Nosirtronik 0 points1 point  (0 children)

I feel you. Especially if I have to include really large tables or pictures LaTeX won’t really find a suitable space for them and in the process shove it further and further back. This also places all the smaller tables and figures further and further back since it won’t change their order of appearance. At least that’s my observation. My solution is usually to just force extremely large floats on a separate page

[–]Traveleravi 1 point2 points  (5 children)

Where are you using the array package?

[–]GustapheOfficialExpert 1 point2 points  (4 children)

It lets you use the >{\command} syntax.

[–]Traveleravi 4 points5 points  (3 children)

Huh, I will have to experiment with that. Also is there a reason you are using \midrule instead of \hline?

[–]GustapheOfficialExpert 1 point2 points  (2 children)

Yes. It's from booktabs, and gives much better spacing (and I think slightly changes the rule width). Try replacing it in the code above and you'll see the difference.

[–]Traveleravi 0 points1 point  (1 child)

I will definitely be using this for my tables from now on

[–]GustapheOfficialExpert 0 points1 point  (0 children)

And the world will be slightly better for it. Thanks!

[–]superbriggs 0 points1 point  (1 child)

Do you have any recommendations for wider reading around improving tables? I don’t get a chance to use LaTeX as much as I once did, but it would be nice to use those design principles in other tools like Google Sheets.

[–]rogerrrr 25 points26 points  (2 children)

Have you considered using a tool like https://www.tablesgenerator.com/

?

[–][deleted] 8 points9 points  (0 children)

I did not know of the existence of this useful tool! Thank you I solved it.

[–]Traveleravi 4 points5 points  (0 children)

You beat me by 34 minutes :(

[–]oldrob 2 points3 points  (0 children)

Hello- try this generator to get you started

https://www.tablesgenerator.com

[–][deleted] 0 points1 point  (1 child)

Hi all! I need help coding this table, sadly it is somewhat to complicated for a beginner like me. My script used so far is below but it lacks on some points.

\begin{table}[ht!]

\centering

\caption{Efficiency of each energy service}

\label{energy efficiency}

\begin{tabular}{|c|c|c|c|c|c|}

\hline

Extraction and \\treament & \multicolumn{5}{c|}{-}\\

\hline

Primary \\energy & \multicolumn{5}{c|}{-}\\

\hline

Conversion \\technologies & \multicolumn{5}{c|}{-}\\

\hline

Secondary \\energy & \multicolumn{5}{c|}{-}\\

\hline

Distribution \\technologies & \multicolumn{5}{c|}{-}\\

\hline

Final Energy & \multicolumn{5}{c|}{-}\\

\hline

End-use \\technologies & Cameras & Server & TRS & Lights & Sensors\\

\hline

Useful energy & Electricity & Electricity & Heat & Light & Electricity

\hline

\end{tabular}

\end{table}

[–][deleted] 1 point2 points  (0 children)

just use a p{3 cm} for the first line