4

I am a beginner in Latex. I use Lyx to create tables and then I export the pdflatex script which I can simply paste in Overleaf. I am trying to create a table as follows.

enter image description here

As you can see the column width for column 4,5 and 8 is unnecessarily wide which takes my table almost to the edge of the page. I used nested table so that the column width decreases, but it seems it does nothing.

Here, is the pdflatex exported from Lyx.

%% LyX 2.3.6.1 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{array}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

\makeatother

\usepackage{babel}
\begin{document}

\begin{table}

\caption{Problem 1: Summary of parameters and relative $L^{2}$ error for different
PINN frameworks\label{tab:Problem-1:-Summary}}

\begin{centering}
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline 
 & Layers & Nodes & %
\begin{tabular}{c}
Boundary\tabularnewline
points\tabularnewline
\end{tabular} & %
\begin{tabular}{c}
Collocation\tabularnewline
points\tabularnewline
\end{tabular} & $\alpha$ & Iterations & %
\begin{tabular}{c}
Relative $L^{2}$\tabularnewline
error\tabularnewline
\end{tabular}\tabularnewline
\hline 
Model 1 & 8 & 20 & 612 & 5800 & 1e-3 & 30k & 0.13599\tabularnewline
\hline 
Model 2 & 8 & 20 & 800 & 2500 & 1e-3 & 30k & NA\tabularnewline
\hline 
Model 3 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.08931\tabularnewline
\hline 
Model 4 & 6 & 512 & 4000 & 4000 & 1e-3 & 10k & 0.10124\tabularnewline
\hline 
Model 5 & 6 & 512 & 4000 & 4000 & 1e-3 & 10k & 0.09557\tabularnewline
\hline 
Model 6 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.06448\tabularnewline
\hline 
Model 7 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.06433\tabularnewline
\hline 
Model 8 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.18741\tabularnewline
\hline 
Model 9 & 6 & 512 & 4000 & 4000 & 2e-5 & 11k & 0.12640\tabularnewline
\hline 
Model 10 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.17577\tabularnewline
\hline 
Model 11 & 6 & 512 & 4000 & 4000 & 1e-3 & 30k & 0.08229\tabularnewline
\hline 
\end{tabular}
\par\end{centering}
\begin{raggedright}
{*} From Model 3 to Model 11, the boundary points and collocation
points are given for per batch.
\par\end{raggedright}
\end{table}
\end{document}

I know I can manually set the column width in centimeters or inches. Isn't there an automated way to set the column width? I have multiple tables and I don't want to tinker them manually.

EDIT 1: Here are the options in Lyx. enter image description here

8
  • Just keeping to "pure" LaTeX, you can use the p column type instead of c, but I've never used LyX so I don't know if you have control over this. A better solution would be to use a package providing that feature, like tabularray or the older tabularx. Is this possible in LyX?
    – Miyase
    Jun 1, 2022 at 8:18
  • I have added the screenshot of table settings in Lyx. Jun 1, 2022 at 8:22
  • Does the "horizontal alignment" option at the top offer a "paragraph" type of column? If yes, that's the p type I was mentioning and it accepts a specified width.
    – Miyase
    Jun 1, 2022 at 8:25
  • I have got Center, Left, Right and At Decimal separator in the horizontal alignment. Jun 1, 2022 at 8:32
  • Assuming that those are the default LaTeX types (except the last one, which is likely provided by siunitx) then you may be out of luck. I'll let people actually familiar with LyX give a proper answer, though. Sorry.
    – Miyase
    Jun 1, 2022 at 8:41

2 Answers 2

4

The problem is due to the preamble of the nested tabulars (for the column heads). You can replace each {c} with {@{]c@{}}, or simpler, use the makecell package and its eponymous command. Furthermore, the table is too wide for the default text width, so I suggest loading geometry. Also, I loaded caption to have a more sensible spacing between the caption and the table.

        \documentclass[english]{article}
        \usepackage[T1]{fontenc}
        \usepackage[latin9]{inputenc}
        \usepackage[showframe]{geometry}
        \usepackage{array, caption}
        \usepackage{makecell}
        \makeatletter

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
        %% Because html converters don't know tabularnewline
        \providecommand{\tabularnewline}{\\}

        \makeatother
        \usepackage{babel}

        \begin{document}

        \begin{table}

        \caption{Problem 1: Summary of parameters and relative $L^{2}$ error for different
        PINN frameworks\label{tab:Problem-1:-Summary}}


        \centering
        \begin{tabular}{|c|c|c|c|c|c|c|c|}
        \hline
         & Layers & Nodes & %
        \begin{tabular}{@{}c@{}}
        Boundary\tabularnewline
        points\tabularnewline
        \end{tabular} & %
        \begin{tabular}{@{}c@{}}
        Collocation\tabularnewline
        points\tabularnewline
        \end{tabular} & $\alpha$ & Iterations & %
        \begin{tabular}{@{}c@{}}
        Relative $L^{2}$\tabularnewline
        error\tabularnewline
        \end{tabular}\tabularnewline
        \hline
        Model 1 & 8 & 20 & 612 & 5800 & 1e-3 & 30k & 0.13599\tabularnewline
        \hline
        Model 2 & 8 & 20 & 800 & 2500 & 1e-3 & 30k & NA\tabularnewline
        \hline
        Model 3 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.08931\tabularnewline
        \hline
        Model 4 & 6 & 512 & 4000 & 4000 & 1e-3 & 10k & 0.10124\tabularnewline
        \hline
        Model 5 & 6 & 512 & 4000 & 4000 & 1e-3 & 10k & 0.09557\tabularnewline
        \hline
        Model 6 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.06448\tabularnewline
        \hline
        Model 7 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.06433\tabularnewline
        \hline
        Model 8 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.18741\tabularnewline
        \hline
        Model 9 & 6 & 512 & 4000 & 4000 & 2e-5 & 11k & 0.12640\tabularnewline
        \hline
        Model 10 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.17577\tabularnewline
        \hline
        Model 11 & 6 & 512 & 4000 & 4000 & 1e-3 & 30k & 0.08229\tabularnewline
        \hline
        \end{tabular}
        \vskip 3ex
        \begin{tabular}{|c|c|c|c|c|c|c|c|}
        \hline
         & Layers & Nodes & %
        \begin{tabular}{@{}c@{}}
        Boundary\tabularnewline
        points\tabularnewline
        \end{tabular} & %
        \begin{tabular}{@{}c@{}}
        Collocation\tabularnewline
        points\tabularnewline
        \end{tabular} & $\alpha$ & Iterations & %
        \begin{tabular}{@{}c@{}}
        Relative $L^{2}$\tabularnewline
        error\tabularnewline
        \end{tabular}\tabularnewline
        \hline
        Model 1 & 8 & 20 & 612 & 5800 & 1e-3 & 30k & 0.13599\tabularnewline
        \hline
        Model 2 & 8 & 20 & 800 & 2500 & 1e-3 & 30k & NA\tabularnewline
        \hline
        Model 3 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.08931\tabularnewline
        \hline
        Model 4 & 6 & 512 & 4000 & 4000 & 1e-3 & 10k & 0.10124\tabularnewline
        \hline
        Model 5 & 6 & 512 & 4000 & 4000 & 1e-3 & 10k & 0.09557\tabularnewline
        \hline
        Model 6 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.06448\tabularnewline
        \hline
        Model 7 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.06433\tabularnewline
        \hline
        Model 8 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.18741\tabularnewline
        \hline
        Model 9 & 6 & 512 & 4000 & 4000 & 2e-5 & 11k & 0.12640\tabularnewline
        \hline
        Model 10 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.17577\tabularnewline
        \hline
        Model 11 & 6 & 512 & 4000 & 4000 & 1e-3 & 30k & 0.08229\tabularnewline
        \hline
        \end{tabular}
        \end{table}

        \end{document} 

enter image description here

3

I'm not familiar with LyX and conversion to html, so I don't know, if proposd solution work well there. Anyway, use of tabularx for table and siunitx for present numbers in sixth (\alpha) column, code is simple and table looks nice:

enter image description here

\documentclass[english]{article}
\usepackage{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage[T1]{fontenc}
%\usepackage[latin9]{inputenc}
\usepackage{babel}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage{siunitx}
\usepackage[skip=0.33\baselineskip]{caption}

\makeatletter
%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}
\makeatother

\begin{document}
    \begin{table}
\caption{Problem 1: Summary of parameters and relative $L^{2}$ error for different PINN frameworks}
\label{tab:Problem-1:-Summary}

    \centering
    \setlength\tabcolsep{4pt}
    \renewcommand\arraystretch{1.2}
\begin{tabularx}{\linewidth}{|C|C|C|C|C|S[table-format=1e2]|C|C|}
    \hline
    & Layers
        & Nodes
            & Boundary points
                &  Collocation points
                    & {$\alpha$}
                        & Iterations
                            & Relative $L^{2}$ error   \\
    \hline
Model 1 & 8 & 20 & 612 & 5800 & 1e-3 & 30k & 0.13599    \\
    \hline
Model 2 & 8 & 20 & 800 & 2500 & 1e-3 & 30k & NA\tabularnewline
\hline
Model 3 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.08931\tabularnewline
\hline
Model 4 & 6 & 512 & 4000 & 4000 & 1e-3 & 10k & 0.10124\tabularnewline
\hline
Model 5 & 6 & 512 & 4000 & 4000 & 1e-3 & 10k & 0.09557\tabularnewline
\hline
Model 6 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.06448\tabularnewline
\hline
Model 7 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.06433\tabularnewline
\hline
Model 8 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.18741\tabularnewline
\hline
Model 9 & 6 & 512 & 4000 & 4000 & 2e-5 & 11k & 0.12640\tabularnewline
\hline
Model 10 & 6 & 512 & 4000 & 4000 & 1e-3 & 20k & 0.17577\tabularnewline
\hline
Model 11 & 6 & 512 & 4000 & 4000 & 1e-3 & 30k & 0.08229\tabularnewline
\hline
\end{tabularx}
\begin{raggedright}
{*} From Model 3 to Model 11, the boundary points and collocation
points are given for per batch.
\par\end{raggedright}
\end{table}
\end{document}

You must log in to answer this question.

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