4

How can I change the data values underneath the angle of incidence heading from being center and change to left.

Currently this:

enter image description here

I want this:

enter image description here

This is the code I have

\documentclass[10pt,twoside]{article}
\usepackage[labelfont=bf, skip=5pt, font=small]{caption}
\usepackage{subcaption}
%for tables
\usepackage{multirow}
\usepackage[table]{xcolor} % load both xcolor and colortbl
\usepackage{tabularx}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\UseTblrLibrary{booktabs}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{sidenotes}
\usepackage{pgfplots}
\usepackage{tocloft}
\usepackage{fancyhdr}
\usepackage{titlesec,titletoc}
\usepackage{pdflscape}
\usepackage{everypage-1x}
\usepackage{amsmath}
\usepackage{threeparttable}

\newcommand\mytab[1]{\smash[b]{%
   \begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}}

\usepackage{wrapfig}
\setlength\evensidemargin{\oddsidemargin}
\usepackage[a4paper, margin=2.56cm]{geometry}

\pgfplotsset{compat=1.18}

\begin{document}
\begin{table}[h]
\centering

\begin{threeparttable}
\begin{tabular}{@{} 
                     S[table-format=2.0] 
                     S[table-format=2.1]
                     S[table-format=2.0]
                *{2}{S[table-format=2.1]} 
                *{2}{S[table-format=1.4,
                       round-precision=4,
                       round-mode=places,
                       %%drop-zero-decimal=true % no longer needed
                       ]} 
                @{}}
              
\toprule
{\mytab{Angle of incidence\\ $i$ ($^\circ$)}} & \multicolumn{4}{c@{}}{Angle of refraction $r$ ($^\circ$)} &
{\multirow{2.4}{*}{$\sin i$}} & 
{\multirow{2.4}{*}{$\sin r$}} \\
\cmidrule(lr){2-5}
& {Trial 1} & {Trial 2} & {Trial 3} & {Average} \\
\midrule
{0}  & {0}    & {0}  & {0}    & {0}    & {0} & {0} \\ % <-- note: "{0}" rather than "0"
{15} & {10.0}  & {10.0} & {10.0}   & {10.0} & 0.173648178 & 0.258819045\\
30 & {19.5} & {20.0} & {19.5} & {19.7} & 0.337095258 & {0.5} \\
{45} & {28.0}   & {28.0} & {28.0}   & {28.0} & 0.469471563 & 0.707106781\\
{60} & {36.0}   & {36.0} & {36.0}   & {36.0} & 0.587785252 & 0.866025404\\
{75} & {40.5} & {40.0} & {40.0}   & {40.2} & 0.645457688 & 0.965925826\\
\bottomrule
\end{tabular}

\caption{Table of results for angle of incidence $i$ and angle of refraction~$r$ between air and an unknown medium}
\end{threeparttable}

\end{table}

\end{document}

enter image description here

11
  • 2
    Are you sure that this a desirable result? The numbers look very off if they aren't properly aligned. That being said, please don't post code fragments, always make a small, but compilable test file instead. Commented Jun 17 at 14:38
  • @samcarter_is_at_topanswers.xyz yes that is my desired result and I have edited code to show whole document.
    – user323614
    Commented Jun 17 at 14:44
  • I'm confused, your code no longer has a table? Commented Jun 17 at 14:45
  • 1
    {0} is a terrible idea, your zeros won't be properly aligned. Commented Jun 17 at 14:57
  • 1
    If you are on it, consider a properly aligned first column, too! Commented Jun 17 at 15:12

1 Answer 1

4

If you really want to mis-align your numbers, replace the nice S column with a left aligned column:

\documentclass[10pt,twoside]{article}
\usepackage[labelfont=bf, skip=5pt, font=small]{caption}
\usepackage{subcaption}
%for tables
\usepackage{multirow}
\usepackage[table]{xcolor} % load both xcolor and colortbl
\usepackage{tabularx}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\UseTblrLibrary{booktabs}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{sidenotes}
\usepackage{pgfplots}
\usepackage{tocloft}
\usepackage{fancyhdr}
\usepackage{titlesec,titletoc}
\usepackage{pdflscape}
\usepackage{everypage-1x}
\usepackage{amsmath}
\usepackage{threeparttable}

\newcommand\mytab[1]{\smash[b]{%
   \begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}}
   

\usepackage{wrapfig}
\setlength\evensidemargin{\oddsidemargin}
\usepackage[a4paper, margin=2.56cm]{geometry}

\pgfplotsset{compat=1.18}

\begin{document}
\begin{table}[h]
\centering

\begin{threeparttable}
\begin{tabular}{@{} 
                     l
                     S[table-format=2.1]
                     S[table-format=2.0]
                *{2}{S[table-format=2.1]} 
                *{2}{S[table-format=1.4,
                       round-precision=4,
                       round-mode=places,
                       round-pad=false
                       ]} 
                @{}}
              
\toprule
{\multirow{2.4}{*}{Angle of incidence $i$ ($^\circ$)}} & \multicolumn{4}{@{}}{Angle of refraction $r$ ($^\circ$)} &
{\multirow{2.4}{*}{$\sin i$}} & 
{\multirow{2.4}{*}{$\sin r$}} \\
\cmidrule(lr){2-5}
& {Trial 1} & {Trial 2} & {Trial 3} & {Average} \\
\midrule
0  & 0    & 0  & 0    & 0    & 0 & 0 \\ % <-- note: "{0}" rather than "0"
15 & 10.0   & 10.0 & 10.0   & 10.0 & 0.173648178 & 0.258819045\\
30 & 19.5 & 20.0 & 19.5 & 19.7 & 0.337095258 & 0.5 \\
45 & 28   & 28.0 & 28.0   & 28.0 & 0.469471563 & 0.707106781\\
60 & 36.0   & 36.0 & 36.0   & 36.0 & 0.587785252 & 0.866025404\\
75 & 40.5 & 40.0 & 40.0   & 40.2 & 0.645457688 & 0.965925826\\
\bottomrule
\end{tabular}

\caption{Table of results for angle of incidence $i$ and angle of refraction~$r$ between air and an unknown medium}
\end{threeparttable}

\end{table}



\end{document}

enter image description here

2
  • 3
    +1 for "If you really want to mis-align your numbers"... :-)
    – Mico
    Commented Jun 17 at 16:35
  • 3
    @Mico Thanks - it looks horrible :) Commented Jun 17 at 16:36

You must log in to answer this question.