2

In relation to my previous question and the code also provided by the user @Zarko for a nice table, I kindly ask for some adjustments such as those shown in the figure below and reported in the main question:

A specific format for nice tables (see comments).

The @Zarko full MWE compilable code is this

\documentclass[a4paper,12pt]{article} % <---
\usepackage{mathtools,amssymb}                % <---
\usepackage{booktabs, 
            makecell}                         % <---
\setcellgapes{3pt}                            % <---
\usepackage{isotope}
\usepackage[table]{xcolor}                    % <---
\arrayrulecolor{teal}                         % <--- 

\usepackage[skip=1ex]{caption}                % <---
    \DeclareCaptionFont{teal}{\color{teal}}   % <---
    \captionsetup[table]{font=bf,             % <---
                         labelfont={teal,bf},
                         singlelinecheck=off}

\begin{document}
    \begin{table}[htb]              % <---
    \makegapedcells                 % <---
    \caption{My fancy table}        % <---
\begin{tabular}{l*{2}{>{$}c<{$}}}   % <---
    \toprule[2pt]                   % toprule thickens you can change according 
                                    % to your taste, for example to 3pt or more
\textbf{Osservabile} & \textbf{Simbolo} & \textbf{Operatore associato}  \\
    \midrule
Posizione           & \bar{r}       & \bar{r}                           \\
Momento             & \bar{p}       & -i\hslash \overline \nabla        \\
Energia potenziale  & \mathcal{U}   & \mathcal{U}(r)                    \\
Energia cinetica    & \mathcal{K}   & -\dfrac{\hslash^2}{2m}\nabla^2    \\
Hamiltoniana        & H             & -\dfrac{\hslash^2}{2m}\nabla^2+\mathcal{U}(r) \\
Energia totale      & E             & -i\hslash\dfrac{\partial}{\partial t}         \\
    \bottomrule
\end{tabular}
    \end{table}

    \begin{table}[htb]
    \caption{My another fancy table}
\makegapedcells
\begin{tabular}{cccc}
    \toprule[2pt]      % <---
\thead{Numeri\\ di massa}     
        & \thead{Elemento\\ chimico}     
                        & \thead{Prodotto\\ iniziale}   
                                                    & \thead{Prodotto\\ finale}\\   % <---
    \midrule
$4n$    &  Torio        &   \isotope[232][90]{Th}   &   \isotope[208][82]{Pb}   \\
$4n+1$  &  Neptunio     &   \isotope[237][93]{Np}   &   \isotope[209][83]{Bi}   \\
$4n+2$  &  Uranio       &   \isotope[238][92]{U}    &   \isotope[206][82]{Pb}   \\
$4n+3$  &  Attinio      &   \isotope[235][92]{U}    &   \isotope[207][82]{Pb}   \\
    \bottomrule
\end{tabular}
    \end{table}

\end{document}

.... with this output:

enter image description here

I would like the following changes to be made as the picture below:

enter image description here

PS: The upper image is obtained by a partial change of its code to be filled in correctly within my book.

%----------------------------------------------------------------------------------
%   NEW NICE TABLE
%----------------------------------------------------------------------------------

\usepackage{booktabs, makecell, 
            threeparttable}       % <---
\setlength\heavyrulewidth{2pt}    % <---
\setlength\lightrulewidth{1.2pt}  % <---

\setcellgapes{3pt}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadgape{}

\arrayrulecolor{teal}
\usepackage[skip=0.5ex]{caption}
    \DeclareCaptionLabelFormat{uc}{\MakeUppercase{#1}~#2}                % <===
    \DeclareCaptionFont{teal}{\color{teal}\fontfamily{urw}\selectfont} % <===
    \captionsetup[table]{font={large,teal,bf},
                         labelformat=uc,                                 % <===
                         singlelinecheck=off}  

a. Compact or shrink or spaciousness the character of the TABLE 12.1 header equivalent to the image of @Zarko, TABLE 1 or 2;

b. Where there is written the label My fancy file table, the character must be newtxtext;

c. The word Observable (table 1 or table 12.1) must be aligned vertically to the left (see red left arrow) with all the rows in the first column.

  • 1
    Could you post the complete code that you've used to obtain this result, please? – Bernard Feb 15 at 23:24
  • @Bernard I have edited my code. I hope that is that all this is what you asked me for. Thank you very much. – Sebastiano Feb 15 at 23:39
  • 1
    Yes, it's fine, thanks. The problem with the link was that which code fragments were used was ambiguous – Bernard Feb 15 at 23:43
5

Here is a code that hopefully solves your problems:

\documentclass[a4paper,12pt]{article} % <---
\usepackage{mathtools,amssymb} % <---
\usepackage{booktabs,
            makecell} % <---
\setcellgapes{3pt} % <---
\usepackage{isotope}
\usepackage[table]{xcolor} % <---
\arrayrulecolor{teal} % <---
\renewcommand{\theadfont}{\normalsize\bfseries}

\usepackage[skip=1ex]{caption} % <---
\DeclareCaptionFont{ntx}{\fontfamily{ntxlf}\selectfont}
    \DeclareCaptionFont{teal}{\color{teal}} % <---
    \captionsetup[table]{font={bf,ntx}, % <---
                         labelfont={teal},
                         singlelinecheck=off}

\begin{document}
    \begin{table}[htb] % <---
    \makegapedcells % <---
    \caption{My fancy table} % <---
\begin{tabular}{l*{2}{>{$}c<{$}}} % <---
    \toprule[2pt] % toprule thickens you can change according
                                    % to your taste, for example to 3pt or more
\thead [l]{Osservabile} & \textbf{Simbolo} & \textbf{Operatore associato} \\
    \midrule
Posizione & \bar{r} & \bar{r} \\
Momento & \bar{p} & -i\hslash \overline ∇ \\
Energia potenziale & \mathcal{U} & \mathcal{U}(r) \\
Energia cinetica & \mathcal{K} & -\dfrac{\hslash²}{2m}∇² \\
Hamiltoniana & H & -\dfrac{\hslash²}{2m}∇²+\mathcal{U}(r) \\
Energia totale & E & -i\hslash\dfrac{∂}{∂ t} \\
    \bottomrule
\end{tabular}
    \end{table}

    \begin{table}[htb]
    \caption{My another fancy table}
\makegapedcells
\begin{tabular}{cccc}
    \toprule[2pt] % <---
\thead{Numeri\\ di massa}
        & \thead{Elemento\\ chimico}
                        & \thead{Prodotto\\ iniziale}
                                                    & \thead{Prodotto\\ finale}\\ % <---
    \midrule
$4n$ & Torio & \isotope[232][90]{Th} & \isotope[208][82]{Pb} \\
$4n+1$ & Neptunio & \isotope[237][93]{Np} & \isotope[209][83]{Bi} \\
$4n+2$ & Uranio & \isotope[238][92]{U} & \isotope[206][82]{Pb} \\
$4n+3$ & Attinio & \isotope[235][92]{U} & \isotope[207][82]{Pb} \\
    \bottomrule
\end{tabular}
    \end{table}

\end{document} 

enter image description here

  • Thank you very much Bernard. Can you then read the comment I have given to Zarko? – Sebastiano Feb 16 at 11:03
  • 1
    I've read, milord! For me, it's unimportant to have the green tick or not: I give answers here (when I can) above all to help, so choose the answer you think is most useful to you. Related to Zarko's answer: my solution also uses the same newtx font for caption label and caption text – I didn't like such an inconsistency of different font within the same line. – Bernard Feb 16 at 11:19
  • Bernard one check for you and for the previous question related to Zarko. :-) Thank you very much. – Sebastiano Feb 16 at 13:14
3

for unknown reason macro \makegapedcells wchange the position of the first column header content to c (center) when a content in a some other column's cell is longer than in column header. this can be considered (to my opinion) as bug in the makecell package.

edit: since @Bernard already suggest workaround for this misbehavior (+1), so i give here only some remarks/suggestions for first two sub questions (regarding caption's fonts):

  1. (question a) do you like to have other, more compact font for caption's label than for caption text? which font you like to have?

    this is very opinion based request. for available fonts see The LaTeX Font Catalogue.

    i would rather stick at the same font for caption's label and text, however if you still persist on different fonts for label and text, than the way of caption formatting is:

    \usepackage[skip=0.5ex]{caption}
    \DeclareCaptionLabelFormat{uc}{\MakeUppercase{#1}~#2}                   
    \DeclareCaptionFont{cond}{\color{teal}\fontfamily{CabinCondensed-TLF}\selectfont}  % for label 
    \DeclareCaptionFont{teal}{\color{teal}\fontfamily{qhv}\selectfont} % for text    
    \captionsetup[table]{font={large},
                         labelformat=uc, 
                         labelfont={cond,bf}, 
                         textfont=teal,
                         singlelinecheck=off}
    

    where instead CabinCondensed-TLF you can use the desired font family name.

  2. (question b) newtxtext sans serif font are based on Helvetica. its font family name is qhv

  3. (question c) is solved by Bernard's answer

\documentclass[a4paper,12pt,italian]{article}
\usepackage{babel}
\usepackage{mathtools,amssymb}
\usepackage{booktabs, makecell,
            threeparttable}       % <---
\setlength\heavyrulewidth{2pt}    % <---
\setlength\lightrulewidth{1.2pt}  % <---

\setcellgapes{3pt}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadgape{}

\usepackage{isotope}
\usepackage[table]{xcolor}
\arrayrulecolor{teal}
\usepackage[skip=0.5ex]{caption}
    \DeclareCaptionLabelFormat{uc}{\MakeUppercase{#1}~#2} 
    \DeclareCaptionFont{cond}{\color{teal}\fontfamily{CabinCondensed-TLF}\selectfont}
\DeclareCaptionFont{teal}{\color{teal}\fontfamily{qhv}\selectfont}
\captionsetup[table]{font={large},
                     labelformat=uc,
                     labelfont={cond,bf},
                     textfont=teal,
                     singlelinecheck=off}

\begin{document}
    \begin{table}[htb]
    \caption{My fancy table}
\makegapedcells
\begin{tabular}{l*{2}{>{$}c<{$}}}
    \toprule
\thead[l]{Osservabile} & \textbf{Simbolo} & \textbf{Operatore associato}  \\
    \midrule
Posizione           & \bar{r}       & \bar{r}                           \\
Momento             & \bar{p}       & -i\hslash \overline \nabla        \\
Energia potenziale  & \mathcal{U}   & \mathcal{U}(r)                    \\
Energia cinetica    & \mathcal{K}   & -\dfrac{\hslash^2}{2m}\nabla^2    \\
Hamiltoniana        & H             & -\dfrac{\hslash^2}{2m}\nabla^2+\mathcal{U}(r) \\
Energia totale      & E             & -i\hslash\dfrac{\partial}{\partial t}         \\
    \bottomrule
\end{tabular}
    \end{table}

    \begin{table}[htb]
    \caption{My another fancy table}
\makegapedcells
\begin{tabular}{cccc}
    \toprule
\thead{Numeri\\ di massa}
        & \thead{Elemento\\ chimico}
                        & \thead{Prodotto\\ iniziale}
                                                    & \thead{Prodotto\\ finale}\\
    \midrule
$4n$    &  Torio        &   \isotope[232][90]{Th}   &   \isotope[208][82]{Pb}   \\
$4n+1$  &  Neptunio     &   \isotope[237][93]{Np}   &   \isotope[209][83]{Bi}   \\
$4n+2$  &  Uranio       &   \isotope[238][92]{U}    &   \isotope[206][82]{Pb}   \\
$4n+3$  &  Attinio      &   \isotope[235][92]{U}    &   \isotope[207][82]{Pb}   \\
    \bottomrule
\end{tabular}
    \end{table}
\end{document}

enter image description here

  • I'm embarrassed now. Which of the two do I have to put the green tick to? They're both fine. Thank you very much. – Sebastiano Feb 16 at 11:02
  • @Sebastiano, you can accept my previous answer (which you used here for question) and here Bernard's (which not addressed caption issues :-) – Zarko Feb 16 at 11:07
  • 1
    @Sebastiano, i edit my answer (again) ... i changed font family for caption label (from Cabin-TLF to CabinCondensed-TLF). – Zarko Feb 16 at 11:22
  • Zarko thank you very much for all and also to Bernard. :-) I have forgotten that yet, I have not put the check for your answer. :-( Now there is. – Sebastiano Feb 16 at 13:13

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.