0

After about 3 hours of looking through related material and failing to find a solution, I've concluded that there isn't a pattern that can be followed to fit a generic table to a generic page. Every solution that I've found on tex.stackexchange for someone's table going off the page has a different solution. so will you help with mine?

Here is a screenshot of what I want it to look like: no description

And here is the code I've manage to piece together so far, but the table goes way off the right side of the page. It's like the width of the widest column gets automatically copied into the "width" field of every other column, and individual column overrides haven't worked so far.

\usepackage{tabularx}
\newcommand{\TableTypeTwo}
{
    \FloatBarrier
    \begin{table}[h]
        \begin{tabularx}{\textwidth}{|C|C|C|C|C|C|C|C|} \hline
            & sin & cos & mul & div & add/sub & sqrt & temporary floats required \\ \hline
            \multicolumn{1}{m{3cm}}{Operation ("complex rotor generation", "quaternion to mat4", etc.)} & \# & \# & \# & \# & \# & \# & \# \\ \hline
        \end{tabularx}
    \end{table}
    \FloatBarrier
}

Which ends up looking like this: enter image description here

Help?

  • Welcome to TeX.SX! Your table has too many columns or they are just too wide! Try to use a wrapping column type – user31729 Oct 11 '15 at 20:37
  • 1
    you could make it easier for people to help by fixing the example so it is a complete document with the needed definitions eg of C – David Carlisle Oct 11 '15 at 20:37
  • unrelated to being too wide it's a really bad idea to use [h] as it gives latex almost nowhere to put the float as it prevents placing it at the top or bottom of a text page or on a page of floats. – David Carlisle Oct 11 '15 at 20:39
  • Oh I see in the image you have defined C to be a 3cm wide column, you can not have that many 3cm wide columns! just use tabular and c – David Carlisle Oct 11 '15 at 20:41
  • "...with the needed definitions eg of C" - Whoops, I forgot that I wrote capital C instead of lowercase c. The definition is something that I found in another post and was trying (and failing) to figure out. \newcolumntype{C}{>{\centering\arraybackslash}m{3cm}} "unrelated to being too wide it's a really bad idea to use [h]..." - I'm still having trouble with the letters used between brackets. Despite their definitions in places like <sharelatex.com/learn/Positioning_images_and_tables>, I still don't fully understand them. I'll remove the [h] for now. – John Cox Oct 11 '15 at 21:06
2

This fits (I mostly just simplified your markup) although the heading in the last column looks horrible, with some knowledge of the subject you should be able to re-word it a bit.

enter image description here

\documentclass[a4paper]{article}
\usepackage{array}
\begin{document}
   \begin{table}
\centering
        \begin{tabular}{|>{\raggedright}p{3cm}|c|c|c|c|c|c|c|} \hline
            & sin & cos & mul & div & add/sub & sqrt & 
\parbox{1cm}{\centering temp\-orary floats required}\\ \hline
Operation ("complex rotor generation", "quaternion to mat4", etc.)
 & \# & \# & \# & \# & \# & \# & \# \\ \hline
        \end{tabular}
    \end{table}

\end{document}

Also I left in the " but that should never be used in LaTeX, with use separate left and right quotes `` '' or use straight quotes (possibly with \texttt in this case)

| improve this answer | |
  • Woot, thanks! BTW, I've seen the ">" symbol used in a few other posts. Is it like piping one command into another in a linux shell? – John Cox Oct 11 '15 at 21:05
  • @JohnCox It is more like specifying an environment variable at the beginning of a command line e.g. ENVVAR=/whatever executable. Except it can come after if you put it the other way. – cfr Oct 11 '15 at 21:30
  • Sp when you did \begin{tabular}{|>{\raggedright}p{3cm}|c|c|c|c|c|c|c|} \hline what was being specified? Was the "|" getting overridden? – John Cox Oct 11 '15 at 21:43
  • @JohnCox this specifies one column of 3cm (that allows linebreaking) (you had specified all columns to be 3cm wide) and 7 columns that are the width of their widest entry, centred. there is no need to specify a width of the table as it will be the natural width of its contents. – David Carlisle Oct 11 '15 at 21:49

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.