[Tex/LaTex] Inserting a table made with ERT into a float in LyX

lyxtables

Is it impossible to insert a table made with ERT into a float in LyX 2.0 such that I can edit the height and placement of the table in my document?

Best Answer

Looking at the table code you posted in your previous question, I'll give some explanation of it, and how it relates to LyX.

\begin{table}[ht]
\caption{Nonlinear Model Results}  
\centering
\begin{tabular}{c c c c}
\hline\hline  
Case & Method\#1 & Method\#2 & Method\#3 \\ [0.5ex]
\hline
1 & 50& 837 & 970 \\
2 & 47 & 877 & 230 \\
3 & 31 & 25 & 415 \\
4 & 35 & 144 & 2356 \\
5 & 45 & 300 & 556 \\ [1ex]
\hline
\end{tabular}
\label{table:nonlin}
\end{table}
  1. The table environment, i.e.

     \begin{table}[ht]
     ...
     \end{table}
    

    This is a float, and it is what you get when you do Insert --> Float --> Table in LyX. The optional argument, i.e. [ht] is the placement specifier, and equivalent to choosing Here if possible and Top of page in the float settings.

  2. The caption, i.e. \caption{...}. This is the same as the caption-box that is placed in floats in LyX by default. You can also get it in LyX with Insert --> Caption.

  3. Centering of the content of the float, i.e.

    \centering
    

    This is (almost) the same as changing the paragraph settings inside the table float to centered alignment, via right-click --> Paragraph settings.

    The difference is that LyX inserts a centering environment, instead of the \centering switch.

  4. The tabular enviroment, i.e.

     \begin{tabular}{c c c c}
     ...
     \end{tabular}
    

    This is what actually produces your table, and is what you get when doing Insert --> Table in LyX.

  5. The label, i.e. \label{table:nonlin}. This is the same as labels in LyX, so you can insert this with Insert --> Label.

The point

If you would like to edit your tables such as this with code rather than the LyX GUI, you really don't need anything more than the tabular environment in an ERT, the rest can just as well be added via the GUI. That could also make cross-referencing easier, as the label will be listed in the GUI. For example as seen in the screenshot below:

enter image description here

You don't have to use the GUI though, you could just have the complete code as above in an ERT. Just don't place it inside a second float, which won't work, and doesn't make sense.

Finally, note that floating environments have nothing to do with the scaling of their contents, so having your table in a float won't help you change its height.

Related Question