LuaLaTeX: horitontal alignment of verbatim-environments inside a tabularx-environment - latex

First, I'm fully aware that my code is probably not the ideal way to realize what I want to do. However I'm not a professional LaTeX User and this is the way I figured out.
I made a minimal example that hopefully works when compiled(compiler: LuaLaTeX) to display my problem.
I'm trying to make a beamer-frame with a tabularx-table, which contains in-line verbatim-environments on the one hand and equation-environments on the other. The "Y" column-type is a modified form of the "X" environment of tabularx, which I found on another Stackoverflow-thread.
The precise problem now is the following: I'd like the verbatim-expressions to be aligned with the equation-expressions or at least to be vertically centered in each cell.
As mentioned, I'm far from being an expert and I've exhausted all of my Ideas, so I'm very thankful for any form of ideas and suggestions. :)
\documentclass[c, 10pt]{beamer}
\usepackage{polyglossia}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\usepackage{placeins}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{nicefrac}
\usepackage{array}
\setdefaultlanguage{english}
\usetheme{JuanLesPins}
\usecolortheme{seahorse}
\newcolumntype{Y}{>{\centering\arraybackslash} X}
\begin{document}
\begin{frame}[fragile, allowframebreaks]{Symbols and Commands}
\begin{block}{\centering \large{Division}}
\begin{table}[h]
\centering
\renewcommand\baselinestretch{0.01}\selectfont
\begin{tabularx}{\textwidth}{Y Y Y}
\toprule
\multicolumn{1}{m{.3\textwidth}}{\centering Code} & \multicolumn{2}{m{.6\textwidth}}{\centering Examples}\\
\midrule
\verb|\dfrac{a}{b}| &
{\begin{equation*}
\dfrac{a}{b}
\end{equation*}} &
{\begin{equation*}
\mathrm{e}^{\dfrac{1}{k_BT}}
\end{equation*}} \\
\verb|\frac{a}{b}| &
{\begin{equation*}
\frac{a}{b}
\end{equation*}} &
{\begin{equation*}
\mathrm{e}^{\frac{1}{k_BT}}
\end{equation*}} \\
\verb|\nicefrac{a}{b}| &
{\begin{equation*}
\nicefrac{a}{b}
\end{equation*}} &
{\begin{equation*}
\mathrm{e}^{\nicefrac{1}{k_BT}}
\end{equation*}} \\
\bottomrule
\end{tabularx}
\end{table}
\end{block}
\end{frame}
\end{document}

To place unnumbered equations in a table, I would rather use inline math instead of equation environments. To get the same rendering of fractions as in equations, add \displaystyle.
Off-topic:
don't load packages multiple times
don't use fragile, allowframebreaks unless they are really necessary for the frame
floating specifier like [H] don't make sense in a document class without floating mechanism
you don't need \centering in beamer tables, they are centred by default
the syntax \large{...} is wrong, \large is a switch and does not take an argument, so it should be \large Division. Anyway it would be better to not put formatting instructions inside an macro argument, but to set the appropriate beamer template that controls the font of the block title
\documentclass[c, 10pt]{beamer}
%\usepackage{polyglossia}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\usepackage{tabularx}
%\usepackage{amsmath}
%\usepackage{amssymb}
%\usepackage{siunitx}
%\usepackage{placeins}
\usepackage{multirow}
\usepackage{booktabs}
%\usepackage{verbatim}
%\usepackage{fancyvrb}
\usepackage{nicefrac}
\usepackage{array}
%\setdefaultlanguage{english}
\usetheme{JuanLesPins}
\usecolortheme{seahorse}
\newcolumntype{Y}{>{\centering\arraybackslash} X}
\setbeamerfont{block title}{size=\large}
\begin{document}
\begin{frame}
\frametitle{Symbols and Commands}
\begin{block}{\centering Division}
\begin{table}
% \centering
% \renewcommand\baselinestretch{0.01}\selectfont
\begin{tabularx}{\textwidth}{Y Y Y}
\toprule
Code & \multicolumn{2}{c}{Examples}\\
\midrule
\verb|\dfrac{a}{b}| &
$\displaystyle\dfrac{a}{b}$ &
$\displaystyle\mathrm{e}^{\dfrac{1}{k_BT}}$ \\\addlinespace
\verb|\frac{a}{b}| &
$\displaystyle\frac{a}{b}$ &
$\displaystyle\mathrm{e}^{\frac{1}{k_BT}}$ \\\addlinespace
\verb|\nicefrac{a}{b}| &
$\displaystyle\nicefrac{a}{b}$ &
$\displaystyle\mathrm{e}^{\nicefrac{1}{k_BT}}$ \\
\bottomrule
\end{tabularx}
\end{table}
\end{block}
\end{frame}
\end{document}

Related

How can I put an equation and an image in the same row? (Latex)

I want to put an equation with cases on the left and its graph on the right, in the same row. I try with different solutions I found on stackoverflow, but any of them could help me. This is the code I wrote in VSC:
\documentclass[12pt]{article}
\usepackage{blindtext}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{subcaption}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{fancyhdr, color}
\usepackage[dvipsnames]{xcolor}
\usepackage[thinc]{esdiff}
\begin{itemize}
\item \textbf{Finestra rettangolare e area unitaria:}
\begin{tabular}{c c}
\begin{equation*} \Pi(t) =
\begin{cases}
1, & -\frac{1}{2} \leq t \leq -\frac{1}{2} \\
0, & altrove \\
\end{cases}
\end{equation*}
&
\includegraphics[scale=0.1]{Rectangular_Function_C.png}
\end{tabular}
But it doesn't work:
Function image
Don't use an equation inside a table cell. You can use inline math like $...$ instead
to vertically align the image with the equation, you can use the valign=m key from the adjustbox package
you shouldn't set multi-letter words in math mode, the kerning will be all wrong. Instead you can use \text{altrove}
\documentclass[12pt]{article}
\usepackage{blindtext}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{subcaption}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{fancyhdr, color}
\usepackage[dvipsnames]{xcolor}
\usepackage[thinc]{esdiff}
\usepackage[export]{adjustbox}
\begin{document}
\begin{itemize}
\item \textbf{Finestra rettangolare e area unitaria:}
\begin{tabular}{c c}
$\displaystyle\Pi(t) =
\begin{cases}
1, & -\frac{1}{2} \leq t \leq -\frac{1}{2} \\
0, & \text{altrove} \\
\end{cases}
$
&
\includegraphics[width=3cm,valign=m]{example-image-duck}
\end{tabular}
\end{itemize}
\end{document}

Problem in twocolumn article below table in latex

I faced a problem writing a twocolumn article in latex. I incorporated a regular table in singlecolumn mode, but when i change it back to doublecolumn below the table, when the text or the proof is large enough to start the second column, it goes over the table , which means that the second column starts at the beginning of the page as if the table doesnt exist. I left as comments the commands that i tried but didnt work.
thank you for your time.
\documentclass[10pt,twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[greek,english]{babel}
\usepackage{alphabeta}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tabularx}
%\usepackage{wraptable}
%\usepackage{wrapfig}
%\usepackage{graphicx}
\usepackage{multicol}
\usepackage{makecell}
\usepackage{amsthm}
%\addto\captionsenglish{
% \renewcommand{\contentsname}{Ξ Ξ΅ΟΞΉΞ΅ΟΟμΡνα}
% }
\newenvironment{absolutelynopagebreak}
{\par\nobreak\vfil\penalty0\vfilneg
\vtop\bgroup}
{\par\xdef\tpd{\the\prevdepth}\egroup
\prevdepth=\tpd}
\author{text}
\title{text}
\date{5/4/2021}
\begin{document}
\maketitle
\section{text}
\par
text
\section{text}
\par
text
\section{text}
\par
text
\section{text}
\par
text
%\newpage
%\begin{absolutelynopagebreak}
\onecolumn
%\end{absolutelynopagebreak}
%\begin{wrapfig}
\begin{table}[t]
\caption{text}
\centering
\begin{tabular}{|m{4cm}|m{4cm}|m{5cm}|}
\hline
text & text & text\\
\hline
text & \parbox{3cm}{\begin{equation*} equation \end{equation*}} & text\\
\hline
text & \parbox{3cm}{\begin{equation*} equation \end{equation*}} & text\\
\hline
text & text & \makecell{text \\ text}\\
\hline
text & \parbox{3cm}{\begin{equation*} equation \end{equation*}} & \makecell{text\\text}\\
\hline
\end{tabular}
\end{table}
%\hrulefill
%\vspace{1cm}
\begin{absolutelynopagebreak}
\twocolumn
\end{absolutelynopagebreak}
\section{text}
% \vspace{10cm}
%\hrulefill
%\clearpage
% {\Large \textbf{5\hskip 0.6cm \selectlanguage{greek} text \textlatin{Maxwell}}}
%\par
\begin{proof}
\begin{equation}
equation
\end{equation}
\begin{equation}
equation
\end{equation}
\begin{equation}
equation
\end{equation}
\begin{equation}
equation
\end{equation}
\end{proof}
\\
text
%\end{wrapfig}
\end{document}
Instead of explicitly switching the text from one column to two columns back and forth within a page, you can use the starred (*) version of the table environment. That will make this table one-column, while the text stays as it is.
\documentclass[10pt,twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[greek,english]{babel}
\usepackage{alphabeta}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{makecell}
\usepackage{amsthm}
\usepackage{lipsum}
\author{text}
\title{text}
\date{5/4/2021}
\begin{document}
\maketitle
\section{text}
\par
text
\section{text}
\par
text
\section{text}
\par
text
\section{text}
\begin{table*}[t]
\caption{text}
\centering
\begin{tabular}{|m{4cm}|m{4cm}|m{5cm}|}
\hline
text & text & text\\
\hline
text & \parbox{3cm}{\begin{equation*} equation \end{equation*}} & text\\
\hline
text & \parbox{3cm}{\begin{equation*} equation \end{equation*}} & text\\
\hline
text & text & \makecell{text \\ text}\\
\hline
text & \parbox{3cm}{\begin{equation*} equation \end{equation*}} & \makecell{text\\text}\\
\hline
\end{tabular}
\end{table*}
\lipsum[1-3]
\section{text}
\lipsum[1-3]
\begin{proof}
\begin{equation}
equation
\end{equation}
\begin{equation}
equation
\end{equation}
\begin{equation}
equation
\end{equation}
\begin{equation}
equation
\end{equation}
\end{proof}
\lipsum[1-2]
\end{document}
The result:

An alternative to write multirow in latex's tabular?

In latex, I know we can use the multirow command like the following,
\begin{table}[!h]
\centering
\begin{tabular}{|c|l|}
\hline
\multirow{2}{*}{A}
& I want to place this sentence in multiple lines, \\
& but don't want to control the linebreak myself \\
\hline
\end{tabular}
\end{table}
I think it is so stupid to control the linebreak myself.
Any other alternative that fits the text width to line width?
\documentclass{article}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabularx}{\linewidth}{|c|X|}
\hline
A
& I want to place this sentence in multiple lines, but don't want to control the linebreak myself \\
\hline
\end{tabularx}
\end{table}
\end{document}

How to rename tables?

I'm writing a paper in Spanish, and I need the name of my tables as "Tabla," not as "Cuadro" which is the current name.
I used the command:
\renewcommand{\tablename}{Tabla}
But it is not working, as nothing changes. I do not have any error when compiling, and the name of my table is still "Cuadro".
\documentclass[journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[spanish, english]{babel}
\usepackage{graphicx}
\usepackage{amsmath}
\spanishdecimal{.}
\begin{document}
\renewcommand{\tablename}{Tabla}
\newcommand\Tstrut{\rule{0pt}{2.6ex}}
\newcommand\Bstrut{\rule[-0.9ex]{0pt}{0pt}}
\begin{table}[h!]
\begin{center}
\caption{Title}
\label{label1}
\centering
\begin{tabular}{c}
\hline \rule[-1ex]{0pt}{2.5ex}something A \Tstrut\Bstrut\\
\rule[-1ex]{0pt}{2.5ex} Something B \Tstrut\Bstrut \\
\rule[-1ex]{0pt}{2.5ex}Something C\Tstrut\Bstrut \\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
There is a special option es-tabla for the babel package.
Some other points:
if the main language of your document is Spanish, this should be the last language loaded in the options of the babel package, e.g. after english
the floating specifier [h!] is almost a guarantee for bad image placement, better use something like [htbp]
\documentclass[journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[english,spanish,es-tabla]{babel}
\usepackage{graphicx}
\usepackage{amsmath}
\spanishdecimal{.}
\newcommand\Tstrut{\rule{0pt}{2.6ex}}
\newcommand\Bstrut{\rule[-0.9ex]{0pt}{0pt}}
\begin{document}
\begin{table}[htbp]
\begin{center}
\caption{Title}
\label{label1}
\centering
\begin{tabular}{c}
\hline \rule[-1ex]{0pt}{2.5ex}something A \Tstrut\Bstrut\\
\rule[-1ex]{0pt}{2.5ex} Something B \Tstrut\Bstrut \\
\rule[-1ex]{0pt}{2.5ex}Something C\Tstrut\Bstrut \\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}

Rotate a page 180 degrees in LaTeX

How can I rotate a page 180 degrees in LaTeX?
\usepackage{lscape}
\begin{landscape}
Some text
\end{landscape}
Or for the whole document:
\documentclass[landscape]{article}
Edit: This would of course only rotate the page by 90°... Sorry. ;)
Have you tried the rotating package?
See http://en.wikibooks.org/wiki/LaTeX/Packages/Rotating
This would rotate the content you put between begin and end. Do you need a designated page to be rotated you can achieve it using \newpage and \clearpage.:
To answer your question in the comments, I don't know how to achieve this within one single environment if you are going to use different types of content (text, images...) within the turn environment. That depends a lot on what you exactly want to achieve.
\documentclass{article}
\usepackage{rotating}
\title{Test document}
\author{Wesho}
\date{18/06/2009}
\begin{document}
\maketitle
\newpage
\begin{rotate}{180}
\includegraphics{graphic.pdf}
\end{rotate}
\clearpage
\end{document}
It depends on the task, but \rotatebox{180} together with \minipage can do the job:
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{rotating}
\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\newpage
\noindent\rotatebox{180}{\noindent\begin{minipage}{\textwidth}
\lipsum[1]
\begin{center}\includegraphics{image01.jpg}\end{center}
\lipsum[2]
\begin{center}
\begin{tabular}{cc}
\hline
1 & 2 \\
3 & 4 \\
\hline
\end{tabular}
\end{center}
\lipsum[3]
\end{minipage}}
\clearpage
\lipsum[1-3]
\end{document}

Resources