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.
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.
Best Answer
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 themakecell
package and its eponymous command. Furthermore, the table is too wide for the default text width, so I suggest loadinggeometry
. Also, I loadedcaption
to have a more sensible spacing between the caption and the table.