2

I am very new to LaTeX. I made this table mostly copying online tables without any understanding. And why are the contents in column not centered? Don't mind some irrelevant packages that I might have added

Here's the code:

\documentclass{article}
\usepackage{graphicx,fancyhdr,amsmath,amssymb,amsthm,subfig,url,hyperref}
\usepackage[margin=1in]{geometry}
\newtheorem{theorem}{Theorem}

\newcommand{\myname}{xxxxxxxx}
\newcommand{\myid}{xxxxxxxx}
\newcommand{\hwNo}{xxxxxxxxxx}
%%% END

\fancypagestyle{plain}{}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RO,LE]{\sffamily\bfseries\large LUMS}
\fancyhead[LO,RE]{\sffamily\bfseries\large CS-210 Discrete Mathematics}
\fancyfoot[LO,RE]{\sffamily\bfseries\large \myname: \myid @lums.edu.pk}
\fancyfoot[RO,LE]{\sffamily\bfseries\thepage}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{1pt}
\renewcommand{\arraystretch}{2}
%--------------------- This is the title of the document. DO NOT CHANGE IT ------------------------

\title{CS-210 \hwNo}
\author{\myname \qquad Student ID: \myid}

%--------------------------------- AFTER Entering the Student and Homework Information, write your answers below  ----------------------------------

\begin{document}

\maketitle

\section{Problem 1}

\begin{table}[h!]
\centering
\caption{A}
\begin{tabular}{|l|l|l|l|l|l|l|l|l|l|l|l|l|}
\hline 
A  &  B  &  C &  $\overline{A}$   &  $\overline{B}$   &  $\overline{C}$  &   A$\cap$B  &   $\overline{A} \cap$C  &   A$ \cap \overline{B}$  &  $\overline{A} \cap \overline{C}$  &   A$\cap$B    $ \cup $ $\overline{A} \cap$C    & $ (\  ( \  A \cap B  )\   \cup  (\ \overline{A} \cap C  )\  )\ \complement $  &  $  (\ A \cap \overline{B}   )\  \cup   (\ \overline{A} \cap \overline{C} )\ $ \\ 
\hline\hline
  1&   1&  1 &       0               &   0 & 0 &1  &0  &0  &0  &1  &0  & 0 \\
  1&  1 &  0 &         0             &   0 & 1 & 1 & 0 & 0 & 0 & 1 & 0 &  0\\
  1&  0 &  1 &           0           &   1 & 0 & 0 & 0 & 1 & 0 & 0 &  1&  1\\
  1&  0 &  0 &             0         &   1 & 1 & 0 & 0 & 1 & 0 & 0 &  1&  1\\
  0&  1 &  1 &         1             &   0 & 0 & 0 & 1 & 0 &  0& 1 &  0&  0\\
  0&  1&   0&            1          &    0 & 1 & 0 & 0 & 0 &  1& 0 &  1&  1\\
  0& 0  &  1 &             1         &   1 & 0 & 0 & 1 & 0 &  0& 1 &  0 & 0\\
 0& 0  &   0&                1      &    1 &1  & 0 & 0 & 0 &  1& 0 &  1 & 1\\
\hline
\end{tabular}
\end{table}

\end{document}

3 Answers3

1

A variant of your table which fits in the text width:

\documentclass{article}

\usepackage{amssymb}
\usepackage[margin=1in]{geometry}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage{caption}

\begin{document}
\begin{table}[h!]
\centering
\caption{A}
\begin{tabular}{*{13}{c}}
  \toprule
  $A$ & $B$ & $C$ & $\overline{A}$ & $\overline{B}$ & $\overline{C}$ & $A\cap B$
      & $\overline{A}\cap C$ & $A\cap\overline{B}$
      & $\overline{A}\cap\overline{C}$
      & \makecell{$A\cap B$\\${}\cup\overline{A}\cap C$}
      & \makecell
          {$\big((A\cap B)$\\${}\cup(\overline{A}\cap C)\big)\complement$}
      & \makecell
          {$(A\cap\overline{B})$\\${}\cup(\overline{A}\cap\overline{C})$} \\ 
  \midrule
  1 & 1 & 1 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 \\
  1 & 1 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 1 & 0 & 0 \\
  1 & 0 & 1 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 & 1 & 1 \\
  1 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 1 \\
  0 & 1 & 1 & 1 & 0 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 \\
  0 & 1 & 0 & 1 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 1 & 1 \\
  0 & 0 & 1 & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 \\
  0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 1 & 0 & 1 & 1 \\
 \bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

Skillmon
  • 60,462
0

I suggest you (a) get rid of all vertical lines (each lines takes up a bit of space, and 14 lines take up quite a bit of space!), (b) simplify the cell headers a bit (mostly, try to use math mode consistently), (c) use c rather than l as the column type for all 13 columns, and (d) employ a tabular* environment instead of the tabular environment.

enter image description here

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{fancyhdr}
\fancypagestyle{plain}{}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RO,LE]{\sffamily\bfseries\large LUMS}
\fancyhead[LO,RE]{\sffamily\bfseries\large CS-210 Discrete Mathematics}
\fancyfoot[LO,RE]{\sffamily\bfseries\large \myname: \myid @lums.edu.pk}
\fancyfoot[RO,LE]{\sffamily\bfseries\thepage}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{1pt}

\usepackage{booktabs} % <-- new
\usepackage{graphicx,amsmath,amssymb,amsthm,subfig}
\newtheorem{theorem}{Theorem}
\newcommand{\myname}{xxxxxxxx}
\newcommand{\myid}{xxxxxxxx}
\newcommand{\hwNo}{xxxxxxxxxx}

\usepackage[hyphens,spaces]{url}
\usepackage[colorlinks,allcolors=blue]{hyperref}
%%% END

%---- This is the title of the document. 
%---- DO NOT CHANGE IT --------------

\title{CS-210 \hwNo}
\author{\myname \qquad Student ID: \myid}

%----- AFTER Entering the Student and Homework 
%----- Information, write your answers below 

\begin{document}
\maketitle   
\section{Problem 1}

\begin{table}[h!]
\setlength\tabcolsep{0pt} % let LaTeX calculate intercol. whitespace
\renewcommand{\arraystretch}{1.5}  % "2" is excessive
\caption{A}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}*{13}{c}}
\toprule
  $A$ 
& $B$ 
& $C$ 
& $\overline{A}$ 
& $\overline{B}$ 
& $\overline{C}$ 
& $A\cap B$ 
& $\overline{A} \cap C$ 
& $A \cap \overline{B}$ 
& $\overline{A} \cap \overline{C}$ 
& $A\cap B \cup \overline{A} \cap C$ 
& $ \overline{(A\cap B) \cup(\overline{A}\cap C)}$ 
& $ (A\cap\overline{B}) \cup (\overline{A}\cap\overline{C} )$ \\
\midrule % **not** \hline\hline
 1& 1 & 1 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 0\\
 1& 1 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 1 & 0 & 0\\
 1& 0 & 1 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 & 1 & 1\\
 1& 0 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 1\\
 0& 1 & 1 & 1 & 0 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0\\
 0& 1 & 0 & 1 & 0 & 1 & 0 & 0 & 0 & 1 & 0 & 1 & 1\\
 0& 0 & 1 & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0\\
 0& 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 1 & 0 & 1 & 1\\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
Mico
  • 506,678
0

The table is math, so it should be array. You can save much space, removing the added spaces after the parentheses and by reducing the padding between columns. Also the vertical rules can (and should) be removed.

\documentclass{article}
\usepackage{graphicx,fancyhdr,amsmath,amssymb,amsthm,subfig,url,hyperref}
\usepackage[margin=1in,headheight=14pt]{geometry}
\usepackage{booktabs}

\newtheorem{theorem}{Theorem}

\newcommand{\myname}{xxxxxxxx}
\newcommand{\myid}{xxxxxxxx}
\newcommand{\hwNo}{xxxxxxxxxx}
%%% END

\fancypagestyle{plain}{}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RO,LE]{\sffamily\bfseries\large LUMS}
\fancyhead[LO,RE]{\sffamily\bfseries\large CS-210 Discrete Mathematics}
\fancyfoot[LO,RE]{\sffamily\bfseries\large \myname: \myid @lums.edu.pk}
\fancyfoot[RO,LE]{\sffamily\bfseries\thepage}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{1pt}
\renewcommand{\arraystretch}{2}
%--------------------- This is the title of the document. DO NOT CHANGE IT ------------------------

\title{CS-210 \hwNo}
\author{\myname \qquad Student ID: \myid}

%--------------------------------- AFTER Entering the Student and Homework Information, write your answers below  ----------------------------------

\begin{document}

\maketitle

\section{Problem 1}

\begin{table}[!htp]
\centering

\caption{A}
\[
\setlength{\arraycolsep}{3.3pt}
\begin{array}{@{}*{13}{c}@{}}
\toprule
A  &  B  &  C &  \overline{A}   &  \overline{B}   &
\overline{C}  &   A\cap B  & \overline{A} \cap C  &
A \cap \overline{B}  &  \overline{A} \cap \overline{C} &
A\cap B \cup \overline{A} \cap C    &
((A \cap B)\cup(\overline{A}\cap C))^\complement  &
(A \cap \overline{B} )\cup (\overline{A} \cap \overline{C} ) \\ 
\midrule
  1&   1&  1 &       0               &   0 & 0 &1  &0  &0  &0  &1  &0  & 0 \\
  1&  1 &  0 &         0             &   0 & 1 & 1 & 0 & 0 & 0 & 1 & 0 &  0\\
  1&  0 &  1 &           0           &   1 & 0 & 0 & 0 & 1 & 0 & 0 &  1&  1\\
  1&  0 &  0 &             0         &   1 & 1 & 0 & 0 & 1 & 0 & 0 &  1&  1\\
  0&  1 &  1 &         1             &   0 & 0 & 0 & 1 & 0 &  0& 1 &  0&  0\\
  0&  1&   0&            1          &    0 & 1 & 0 & 0 & 0 &  1& 0 &  1&  1\\
  0& 0  &  1 &             1         &   1 & 0 & 0 & 1 & 0 &  0& 1 &  0 & 0\\
 0& 0  &   0&                1      &    1 &1  & 0 & 0 & 0 &  1& 0 &  1 & 1\\
\bottomrule
\end{array}
\]
\end{table}

\end{document}

Note the setting of headheight and the use of booktabs for improving the quality of the table.

enter image description here

egreg
  • 1,121,712