2
\documentclass[12pt] {article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{longtable}

\begin{document}
    \begin{longtable}{|c|c|c|}
    \hline
    \pmb{Operation} & \pmb{Codes}   & \pmb{Output}\\\hline
    \endhead
    \multirow{3}{*}{Transpose}  &{\fontfamily{qcr}\selectfont A=Matrix([[1,2,3],[3,2,1],[1,1,5]])}  & \multirow{3}{*}{$\left(
    \begin{matrix}
        1 &2 &3\\
        3 &2 &1\\
        1 &1 &5
    \end{matrix}
    \right)$}\\

    & {\fontfamily{qcr}\selectfont B=A.transpose()} &\\
    & {\fontfamily{qcr}\selectfont show(B)} &\\\hline
    \multirow{2}{*}{Determinant}    &{\fontfamily{qcr}\selectfont A=Matrix([[1,2,3],[3,2,1],[1,1,5]])}  & \multirow{2}{*}{-16}\\
    & {\fontfamily{qcr}\selectfont A.det()} &   \\\hline 
    
    \multirow{3}{*}{Adjoint}    &{\fontfamily{qcr}\selectfont A=Matrix([[1,2,3],[3,2,1],[1,1,5]])}  & \multirow{3}{*}{$\left(
        \begin{matrix}
            1 &2 &3\\
            3 &2 &1\\
            1 &1 &5
        \end{matrix}
        \right)$}\\
    & {\fontfamily{qcr}\selectfont B=A.adjugate()}  &\\
    &{\fontfamily{qcr}\selectfont show(B)}  &\\\hline
\end{longtable}
\end{document}

It is appearing through my coding that

  1. in the 3rd column (Output column), then parenthesis touched the top and bottom horizontal lines
  2. also in the mid column, the lines are not left aligned. How can I solve these problems?
4
  • you have \begin{longtable}{|c|c|c|} so three centred columns use l if you want left. same as tabular or array Mar 11 at 19:44
  • @DavidCarlisle but with this, Codes will also be left aligned which I was not seeking
    – Manjoy Das
    Mar 11 at 19:46
  • 3
    as with tabular \multicolumn{1}{c|}{\textbf{Codes}} will give a centred heading. don't use \pmb !!!! Mar 11 at 19:50
  • @DavidCarlisle that's really nice!!
    – Manjoy Das
    Mar 11 at 20:01

1 Answer 1

2

Here's a solution that doesn't require all those \fontfamily{qcr}\selectfont directives.

enter image description here

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multirow}
%%%\usepackage{multicol} % not needed
\usepackage{longtable}

% new:
\usepackage{array,courier}

\begin{document}
\begin{longtable}{| l | >{\ttfamily}l | c |}
    
\hline
\textbf{Operation} & \multicolumn{1}{c|}{\textbf{Codes}}  & \textbf{Output}\\
\hline
\endhead
    
% body of table:
    \multirow{3}{*}{Transpose}  & 
    A=Matrix([[1,2,3],[3,2,1],[1,1,5]])  & 
    \multirow{3}{*}{\small $
        \begin{pmatrix}
            1 &2 &3\\
            3 &2 &1\\
            1 &1 &5
        \end{pmatrix}
        $} \\

    & B=A.transpose() & \\
    & show(B) & \\
    \hline
    \multirow{2}{*}{Determinant}    &
    A=Matrix([[1,2,3],[3,2,1],[1,1,5]])  & 
    \multirow{2}{*}{$-16$}\\
    & A.det() & \\
    \hline  
    \multirow{3}{*}{Adjoint}    &
    A=Matrix([[1,2,3],[3,2,1],[1,1,5]])  & 
    \multirow{3}{*}{\small $
        \begin{pmatrix}
            1 &2 &3\\
            3 &2 &1\\
            1 &1 &5
        \end{pmatrix}
        $} \\
    & B=A.adjugate()  & \\
    & show(B)  & \\
\hline
\end{longtable}
\end{document}

Addendum to address the OP's follow-up query: The two main macros provided by LaTeX for drawing horizontal lines in table-like structures -- \hline and \cline -- are not particularly sophisticated. In particular, the spacing between lines drawn by \hline and \cline and the material above/below the lines is frequently woefully inadequate. You've encountered this yourself, haven't you?

Now, one could try a "bandaid approach" to fixing this issue, by inserting some vertical whitespace padding, by hand, above or below various lines. I would like to recommend that you consider doing something very different: Load the booktabs package and learn to use its user-level macros: \toprule, \midrule, \bottomrule, \cmidrule, and \addlinespace. Whitespace can be every bit as effective at forming a visual separator as a black line can. A happy side-effect of using the macros of the booktabs package is that it's hardly ever necessary to contemplate engaging in the kind of visual formatting you are mentioning in your follow-up comments.

Oh, getting rid of all vertical rules is also something that you should become very familiar with. Trust me, those vertical lines won't be missed.

enter image description here

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multirow}
%%%\usepackage{multicol} % not needed
\usepackage{longtable}

% new:
\usepackage{array,courier,booktabs}

\begin{document}
\begin{longtable}{@{} l >{\ttfamily}l c @{}}
    
    \toprule
    \textbf{Operation} & 
    \multicolumn{1}{c}{\textbf{Codes}} & 
    \textbf{Output}\\
    \midrule
    \endhead

    \bottomrule 
    \endlastfoot
    
% body of table:
    \multirow{3}{*}{Transpose} & 
    A=Matrix([[1,2,3],[3,2,1],[1,1,5]]) & 
    \multirow{3}{*}{$
    \begin{pmatrix}
        1 &2 &3\\
        3 &2 &1\\
        1 &1 &5
    \end{pmatrix}$} \\
   
  & B=A.transpose() &\\
  & show(B) & \\
    \addlinespace
    
    \multirow{2}{*}{Determinant} &
    A=Matrix([[1,2,3],[3,2,1],[1,1,5]]) & 
    \multirow{2}{*}{$-16$}\\
  & A.det() & \\
    \addlinespace 
    
    \multirow{3}{*}{Adjoint} &
    A=Matrix([[1,2,3],[3,2,1],[1,1,5]]) & 
    \multirow{3}{*}{$
    \begin{pmatrix}
        1 &2 &3\\
        3 &2 &1\\
        1 &1 &5
    \end{pmatrix}$}\\
  & B=A.adjugate() & \\
  & show(B) & \\

\end{longtable}
\end{document}
7
  • how can I manually set arbitrary cell height for a particular cell in this table?
    – Manjoy Das
    Mar 11 at 20:17
  • @ManjoyDas - Please be a bit more specific. Which cell do you have in mind, and how large might the "arbitrary cell height" be?
    – Mico
    Mar 11 at 20:19
  • the (3,2) cell with +0.5 cm height
    – Manjoy Das
    Mar 11 at 20:21
  • @ManjoyDas - Am I interpreting your request correctly as you wanting to adjust the height of cell (2,2) but not the heights of the adjoining cells (2,1) and (2,3)? I honestly don't know how that might be accomplished.
    – Mico
    Mar 11 at 20:23
  • to be precise I want to increase the height of the Determinant row by 0.5 cm
    – Manjoy Das
    Mar 11 at 20:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .