Reputation: 386
How are you,
I am using Google Colab to solve exercises of my university in combination with the pandas library.
According to the documentation of Colab to be able to show some formula using LATEX, you have to introduce it between two dollar signs ($) which works correctly for me. For example here an image of a part of my document that works without problems.
The drawback occurs when I try to generate a table with some values that will serve to explain the problem I am solving but are not rendered. Next I show the image of how it is rendered
As a test try to render a matrix that is the closest thing to a table and I have no problems.
Can the problem occur because Colab is not supporting or is blocking the rendering of tables?
What would be the correct way to generate a table within the text part of Google Colab?
I have found solutions for how to use LATEX in other stackoverflow responses but these solutions do not work for me since I want the table to appear in the text part of my colab document and not within the code part.
Thank you for your answers.
Upvotes: 3
Views: 16096
Reputation: 161
Just play around with |c| 's and \hline 's to get nice-looking tables using array in latex.
Below are a few handy templates (works in colab).
Template 1
\begin{array}{|c|c|} \hline
column1 & column2 & column3 & column4 \\ \hline
foo & bar & foo & bar \\
foo & bar & foo & bar \\
foo & bar & foo & bar \\ \hline
\end{array}
Template 2
\begin{array}{|c|} \hline
column1 & column2 & column3 & column4 \\ \hline
foo & bar & foo & bar \\
foo & bar & foo & bar \\
foo & bar & foo & bar \\ \hline
\end{array}
Template 3
\begin{array}{c} \hline
column1 & column2 & column3 & column4 \\ \hline
foo & bar & foo & bar \\
foo & bar & foo & bar \\
foo & bar & foo & bar \\ \hline
\end{array}
Template 4
\begin{array}{|c|c|} \hline
column1 & column2 & column3 & column4 \\ \hline
foo & bar & foo & bar \\ \hline
foo & bar & foo & bar \\\hline
foo & bar & foo & bar \\ \hline
\end{array}
Upvotes: 2
Reputation: 53
In co labs using latex for Big O notation, this worked for me
Math(r'\displaystyle \\
\begin{array}{|c|c|c|c|c|c|c|c|}\hline\\ \\
\mathcal{} & \mathcal{A} & \mathcal{B} & \mathcal{O} & o & \Omega & \omega & \Theta \\ \hline\\ \\
a & lg^kn & n^\epsilon & yes\; no & yes\; no & yes\; no & yes\; no & yes\; no \\ \hline\\ \\
b & n^k & c^n & yes\; no & yes\; no & yes\; no & yes\; no & yes\; no \\ \hline\\ \\
c & \sqrt{n} & n^{sin n} & yes\; no & yes\; no & yes\; no & yes\; no & yes\; no \\ \hline\\ \\
d & 2^n & 2^{n/2} & yes\; no & yes\; no & yes\; no & yes\; no & yes\; no \\ \hline\\ \\
e & n^{lg c} & c^{lg n} & yes\; no & yes\; no & yes\; no & yes\; no & yes\; no \\ \hline\\ \\
f & lg(n!) & lg(n^n) & yes\; no & yes\; no & yes\; no & yes\; no & yes\; no \\ \hline\\
\end{array}\\')
Upvotes: 2
Reputation: 11547
Use array
instead of tabular
. Tabular environments can be used to display tables that are typeset as text in math mode, but the most common is the use of arrays.
For some unknown reason, in google colab, array is supported and considered as a valid LaTeX command, while tabular is considered as a code sample.
\begin{array}{ccc}
foo&bar&baz\\
1&2&3
\end{array}
\begin{tabular}{ccc}
foo&bar&baz\\
1&2&3
\end{tabular}
Array enters TeX math mode and even plain text is typeset in math mode. To avoid this behavior you can use \text{my text}
\begin{array}{ccc}
\text{foo}&\text{bar}&\text{baz}\\
1&2&3
\end{array}
Upvotes: 9