I was trying to recreate a table from a question with some modifications (irrelevant to the substance in this question). The table which I could build looks like this:
There are still several issues with this table, such as
- the vertical spacing between cells,
- the color overflowing the sides and not filling the entire cells.
But in this question, I would like to focus only on the table heading, or caption. I would like to
- align the caption so that it starts where the table starts;
- table should remain in the center of page;
- I would not like to stretch the table heading or caption (so some whitespace should remain in this case to the right of the heading.
Other similar questions generally align both the caption and and to left, that would not work here.
Any ideas of what I should add or modify? Minimally invasive procedures are preferred.
\documentclass[12pt]{article}
\usepackage[labelsep=period, tableposition=top, labelfont=bf]{caption}
\usepackage[table]{xcolor} %for cell colour
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{tabu} %for \cellcolor to work inside \rowstyle
\usepackage{siunitx} %for the case when the table had lots of numbers to align (not used here)
\makeatletter\usepackage{microtype}\g@addto@macro@verbatim{\microtypesetup{activate=false}}\makeatother%
\renewcommand\cellalign{cr} %align inside \makecell
\newcolumntype{N}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{O}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
} %to make entire row boldface/color with one command instead of one at a time
\begin{document}
\begin{table}[!htbp]
\caption{Title for your table goes here}
\vspace{-0.5em}
\centering
\makebox[\textwidth][c]{\begin{tabular}{@{} Nc|Oc|Oc|Oc|Oc @{}}
\toprule
\rowstyle{\bfseries\cellcolor{cyan!70}}
{Parabola} & {Curve} & {Focus} & {Directrix} & {Vertex}\
\midrule
$x^2 = 4py$ & \makecell{up if $p > 0$ \ down if $p < 0$} & $F(0, p)$ & $y = -p$ & $V(0, 0)$\
\cline{1-5}%horisontal line
$y^2 = 4px$ & \makecell{right if $p > 0$\ left if $p < 0$} & $F(p, 0)$ & $x = -p$ & $V(0, 0)$\
\bottomrule
\end{tabular}}
\label{table: label for table}
\end{table}
\end{document}



tabupackage as it currently is unmaintained and you might experience some unintended side effects. Also, please kaap in mind, that the horizonal lines from the booktabs package were designed to be used without vertical lines. – leandriis Apr 24 '21 at 14:43tabu) and nothing changed, no errors popped up. This is strange; before I could not compile without it. I'll try to avoid it per your suggestion, thank you. I am not sure what you mean by 'horizonal lines from the booktabs package were designed to be used without vertical lines'. Do you mean that I should use them only in tables which do not have any vertical lines? – Linear Christmas Apr 24 '21 at 14:55booktabspackage documentation explicitly states: "More importantly the rules generated by the new commands are in no way guaranteed to connect with verticals generated by{|}characters in the preamble.This is a feature (see above). You should not use vertical rules in tables, end of story." So yes, use horizontal lines from thebooktabspackage only in tables that don't use vertical lines. (For most tables you don't really need vertical lines anyways.) – leandriis Apr 24 '21 at 15:04