Multicolumns tables in LaTeX writing are not in correct order - charts

I am writing an article and the template is in LaTeX, and I need to insert a multicolumn table, the problem is, I have knowledgement just with the basics about LaTeX writing and i am finding some trouble with the organisation of the columns.
This is how the table should look like (image inside Word doc): Word
And this is how the code that i am using is being compiled inside LaTeX: LaTeX
Here is the code:
\begin{table*}[!htb]
\centering%
\caption{ParĂ¢metros obtidos para o ajuste utilizando o modelo de Langmuir.}%
\label{tab:resul}
\centering%
\begin{tabular}{c c c c}
\hline
Modelo de Langmuir:
\begin{minipage}{7cm}{\begin{equation}\label{eq:Uxy}
\frac{\\Qmax\ K_L Ceq}{\\1\ +K_L Ceq} = Qe
\end{equation}}
\end{minipage} \\
\cline{1-4}
\multicolumn{2}{c|}{\textbf{HDL Calc}} & \multicolumn{2}{c}{\textbf{HDL SDS Calc}} \\
\hline
Qmax & K(L/mg) & Qmax(mg/g) & K(L/mg)\\
\hline
690,6 & 0,011 & 132,3 & 0,136\\
\bottomrule
\addlinespace
\end{tabular}
\fonte{Autoria prĂ³pria (2021).}
\end{table*}
Any help with the code?

Related

\hline issue with LaTex when importing table from different .tex file into a tabular environment

I'm having an issue where at certain points using the \hline function creates an error and instead displays the word "height" where there should be a line. This is happening only when I use an /hline immediately after using a \input{".../filename.tex"} command in a tabular environment. Interestingly, though, adding an \hline to the last row of the file I am importing produces an \hline properly. Does anyone have an idea why this may be the case and what I can do to fix it so that I can add the \hline to the main file and not the files I'm importing. Note that I use TexMaker and MiKTeX
Here are some examples of my code that doesn't work:
\documentclass{12pt, english}{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{tocvsec2}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{subfloat}
\usepackage{subcaption}
\usepackage{enumitem}
\usepackage{tabularx}
\usepackage{tabulary}
\usepackage{tabu}
\usepackage{titlesec}
\usepackage{tocloft}
\begin{document}
\begin{table}
\caption{Caption} \label{tab:label} \centering
\begin{tabular}{lccc}
\hline
\import{".../filename.tex"}
\hline
\end{tabular}
\begin{minipage}{0.95}
Notes are here
\end{minipage}
\end{table}
\end{document}
where filename.tex looks like this (with nothing else):
& Mean & SD & N \\
\midrule
Var 1 & 1 & 0 & 1000 \\
Var 2 & 1 & 0 & 1000 \\
Var 3 & 1 & 0 & 1000 \\
Var 4 & 1 & 0 & 1000 \\
Var 5 & 1 & 0 & 1000 \\
When I move the last \hline to the end of filname.tex, however, it works fine.
You can use the same trick as in https://tex.stackexchange.com/a/50700/36296
Other problems:
the syntax \documentclass{12pt, english}{article} is wrong
the booktabs package is missing
missing unit in \begin{minipage}{0.95}
you really, really, really shouldn't use the tabu package, it is more or less completely broken
don't load the same package multiple times
\documentclass[12pt, english]{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{tocvsec2}
\usepackage{graphicx}
\usepackage{multirow}
%\usepackage{tabularx}
\usepackage{subfloat}
\usepackage{subcaption}
\usepackage{enumitem}
\usepackage{tabularx}
\usepackage{tabulary}
%\usepackage{tabu}
\usepackage{titlesec}
\usepackage{tocloft}
\usepackage{booktabs}
\begin{filecontents*}[overwrite]{test.tex}
& Mean & SD & N \\
\midrule
Var 1 & 1 & 0 & 1000 \\
Var 2 & 1 & 0 & 1000 \\
Var 3 & 1 & 0 & 1000 \\
Var 4 & 1 & 0 & 1000 \\
Var 5 & 1 & 0 & 1000 \\
\end{filecontents*}
\makeatletter
\newcommand\primitiveinput[1]
{\##input #1 }
\makeatother
\begin{document}
\begin{table}
\caption{Caption} \label{tab:label} \centering
\begin{tabular}{lccc}
\hline
\primitiveinput{test}
\hline
\end{tabular}
\begin{minipage}{0.95cm}
Notes are here
\end{minipage}
\end{table}
\end{document}

Display complicated Latex in a message box in Matlab results in error

I want to display some Latex output in a messagebox.
The Latex is this:
\left|\begin{array}{l}
u_{tt}=5u_{xx},\quad t>0,\quad 0<x<7 \\
\left.u\right|_{t=0} = \left\{\begin{array}{ll}
\arctan{\left[\left(x^2-11x+30\right)^2\right]}, & x\in[5,6] \\
0, & x\in[0,5)\cup(6,7]
\end{array}\right. \\
\left.u_t\right|_{t=0}=0,\quad 0\leq x\leq7 \\
\left.u_x\right|_{x=0}=0,\quad \left.u_x\right|_{x=7}=0\,\quad t\geq 0\\
\end{array}\right.
I tried this but it's not working:
CreateStruct.Interpreter = 'tex';
CreateStruct.WindowStyle = 'modal';
h = msgbox("\left|\begin{array}{l}"...
"u_{tt}=5u_{xx},\quad t>0,\quad 0<x<7 \\"...
"\left.u\right|_{t=0} = \left\{\begin{array}{ll}"...
"\arctan{\left[\left(x^2-11x+30\right)^2\right]}, & x\in[5,6] \\"...
"0, & x\in[0,5)\cup(6,7]"...
"\end{array}\right. \\"...
"\left.u_t\right|_{t=0}=0,\quad 0\leq x\leq7 \\"...
"\left.u_x\right|_{x=0}=0,\quad \left.u_x\right|_{x=7}=0\,\quad t\geq 0\\"...
"\end{array}\right.","Task",CreateStruct);
Am I doing something wrong or it's just impossible to put such complicated code in a messagebox? It seems that msgbox does not support multiline strings as arguments.

Caption not displaying table

When I use kable to create a table in my Rnw file, the table outputs as expected. However when I include the caption, the table ceases to output at all. Below is my latex and sample knitr chunk.
\documentclass[titlepage]{article}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
\usepackage{afterpage}
\usepackage{booktabs}
\usepackage{longtable}
\pagecolor{ForestGreen}\afterpage{\nopagecolor}
\color{white}
\title{%
\noindent\makebox[\linewidth]{\rule{9cm}{0.9pt}}
\huge \textbf{\textit{Key Distributor Report}}\\
\LARGE \vspace{2mm} \textbf{\textit{A detailed quarterly review}} \\
\noindent\makebox[\linewidth]{\rule{9cm}{0.9pt}}
\vspace{6mm} \LARGE Macdonald Corp.}
\pagenumbering{arabic}
\begin{document}
\maketitle
\color{black}
\newpage
\tableofcontents
\newpage
\section{Overview of Key Distributors}
\section{Company A}
\subsection{National Overview}
\subsubsection{Account base structure}
<<
tester, echo=FALSE, message=FALSE, warning=FALSE, results='asis',fig.height=3, fig.width=3, fig.align='center', eval=TRUE >>=
library(knitr)
kable(head(mtcars[,1:3]), booktabs=TRUE, caption='This is a caption')
#
\end{document}
This seems to be a problem of coloring the texts. If you try to select all content in the pdf you realize, that the table is actually there, but the text is white. So simply change the way of coloring the title page (use \color on \maketitle instead of \title):
\documentclass[titlepage]{article}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
\usepackage{afterpage}
\usepackage{booktabs}
\usepackage{longtable}
\pagecolor{ForestGreen}\afterpage{\nopagecolor}
\title{%
\noindent\makebox[\linewidth]{\rule{9cm}{0.9pt}}
\huge \textbf{\textit{Key Distributor Report}}\\
\LARGE \vspace{2mm} \textbf{\textit{A detailed quarterly review}} \\
\noindent\makebox[\linewidth]{\rule{9cm}{0.9pt}}
\vspace{6mm} \LARGE Macdonald Corp.}
\pagenumbering{arabic}
\begin{document}
{\color{white}%
\maketitle
}
\color{black}
\newpage
\tableofcontents
\newpage
\section{Overview of Key Distributors}
\section{Company A}
\subsection{National Overview}
\subsubsection{Account base structure}
<<tester, echo=FALSE, message=FALSE, warning=FALSE,results='asis',fig.height=3, fig.width=3, fig.align='center', eval=TRUE >>=
library(knitr)
library(kableExtra)
library(dplyr)
kable(head(mtcars[,1:3]), booktabs=T, caption='This is a caption') %>%
kable_styling(latex_options = "hold_position")
#
\end{document}

seems that mathtype doesn't parse a simple amsmath code or maybe the formula is too big to be processed by mathtype at once?

I want to create something like this in MS Word by MathType 6.9
The code that I'm using is:
\documentclass[a4paper]{book}
\usepackage{geometry}
\usepackage{amsmath}
\begin{document}
\begin{align}
T_4 &= \langle \underline{k}\,.\,\underline{k}^{*^T} \rangle=
\left\langle
\begin{bmatrix}
\left|k_1\right|^2 & k_1k_2^* & k_1k_3^* & k_1k_4^* \\
k_2k_1^* & \left|k_2\right|^2 & k_2k_3^* & k_2k_4^* \\
k_3k_1^* & k_3k_2^* & \left|k_3\right|^2 & k_3k_4^* \\
k_4k_1^* & k_4k_2^* & k_4k_3^* & \left|k_4\right|^2
\end{bmatrix}
\right\rangle
\\
&=\frac{1}{2}
\begin{aligned}[t]
& \left[\begin{matrix}
\langle|S_{XX}+S_{YY}|^2\rangle &
\langle(S_{XX}+S_{YY})(S_{XX}-S_{YY})^*\rangle &\\
\langle(S_{XX}-S_{YY})(S_{XX}+S_{YY})^*\rangle &
\langle|S_{XX}-S_{YY}|^2\rangle & \cdots\cdots\\
\langle(S_{XY}+S_{YX})(S_{XX}+S_{YY})^*\rangle&
\langle(S_{XY}+S_{YX})(S_{XX}-S_{YY})^*\rangle & \cdots\cdots\\
\langle j(S_{XY}-S_{YX})(S_{XX}+S_{YY})^*\rangle &
\langle j(S_{XY}-S_{YX})(S_{XX}-S_{YY})^*\rangle &
\end{matrix}\right.\\
& \left.\begin{matrix}
& \langle(S_{XX}+S_{YY})(S_{XY}+S_{YX})^*\rangle
& \langle -j(S_{XX}+S_{YY})(S_{XY}-S_{YX})^*\rangle\\
\cdots\cdots& \langle(S_{XX}-S_{YY})(S_{XY}+S_{YX})^*\rangle
& \langle -j(S_{XX}-S_{YY})(S_{XY}-S_{YX})^*\rangle\\
\cdots\cdots& \langle|S_{XY}+S_{YX}|^2\rangle
& \langle-j(S_{XY}+S_{YX})(S_{XY}-S_{YX})^*\rangle\\
& \langle j(S_{XY}-S_{YX})(S_{XY}+S_{YX})^*\rangle
& \langle|S_{XY}-S_{YX}|^2\rangle
\end{matrix}\right]
\end{aligned}
\end{align}
\end{document}
It's perfect when used in LaTeX and gives the following pdf result:
but unfortunately when I try to copy and paste the code between \begin{document} and \end{document} in MathType to create the same expression in word, I get the result:
It seems that MathType doesn't parse the codes \begin{aligned}[t] and \end{aligned} and as you know these are just amsmath packages code.
Do you know of any way -modifying the code or mathtype settings- to solve this problem?
Or do you have another suggestion to embed Latex equation into MS Word 2010?
Here is a toned-down version of your construction that doesn't use aligned:
\documentclass{article}
\usepackage[margin=1in]{geometry}% Just for this example
\usepackage{amsmath}
\begin{document}
\begin{align}
T_4 &= \langle \underline{k}\,.\,\underline{k}^{*^T} \rangle=
\left\langle
\begin{bmatrix}
|k_1|^2 & k_1k_2^* & k_1k_3^* & k_1k_4^* \\
k_2k_1^* & |k_2|^2 & k_2k_3^* & k_2k_4^* \\
k_3k_1^* & k_3k_2^* & |k_3|^2 & k_3k_4^* \\
k_4k_1^* & k_4k_2^* & k_4k_3^* & |k_4|^2
\end{bmatrix}
\right\rangle \\
&= \frac{1}{2}
\left[\begin{matrix}
\langle|S_{XX}+S_{YY}|^2\rangle &
\langle(S_{XX}+S_{YY})(S_{XX}-S_{YY})^*\rangle &\\
\langle(S_{XX}-S_{YY})(S_{XX}+S_{YY})^*\rangle &
\langle|S_{XX}-S_{YY}|^2\rangle & \cdots\cdots\\
\langle(S_{XY}+S_{YX})(S_{XX}+S_{YY})^*\rangle&
\langle(S_{XY}+S_{YX})(S_{XX}-S_{YY})^*\rangle & \cdots\cdots\\
\langle j(S_{XY}-S_{YX})(S_{XX}+S_{YY})^*\rangle &
\langle j(S_{XY}-S_{YX})(S_{XX}-S_{YY})^*\rangle &
\end{matrix}\right. \nonumber \\
& \phantom{{}= \frac{1}{2}}
\left.\begin{matrix}
& \langle(S_{XX}+S_{YY})(S_{XY}+S_{YX})^*\rangle
& \langle -j(S_{XX}+S_{YY})(S_{XY}-S_{YX})^*\rangle\\
\cdots\cdots& \langle(S_{XX}-S_{YY})(S_{XY}+S_{YX})^*\rangle
& \langle -j(S_{XX}-S_{YY})(S_{XY}-S_{YX})^*\rangle\\
\cdots\cdots& \langle|S_{XY}+S_{YX}|^2\rangle
& \langle-j(S_{XY}+S_{YX})(S_{XY}-S_{YX})^*\rangle\\
& \langle j(S_{XY}-S_{YX})(S_{XY}+S_{YX})^*\rangle
& \langle|S_{XY}-S_{YX}|^2\rangle
\end{matrix}\right]
\end{align}
\end{document}
It's not possible to test this without access to MathType. So, while the above doesn't use aligned, you may have to remove some commands that are unknown to MathType.

Write string as it is to a file in Matlab

In a matlab script, I'm generating a latex table. A part of that table for example looks likes this.
\multirow{2}{*}{\textbf{b1}}
&
2 & 3 & 10092 & 10763 & 103390 & 2797 & 2929 & 3008 & 5\% & 8\% \\
& 4 & 2 & 20184 & 10763 & 74508 & 1830 & 1970 & 2029 & 8\% & 11\% \\
This string is saved in variable str. Now when I try to write str to a file by using the following code.
f = fopen( 'report\results.tex', 'w' );
fprintf( f, str );
fclose(f);
I get the following warning.
Warning: Invalid escape sequence appears in format string.
See help sprintf for valid escape sequences.
That is probably due to many backslash characters in my string, which is used as escape sequence. Now how can I print this string to a file as it is.
escape the backslashes and percent signs:
str = strrep(str,'\','\\');
str = strrep(str,'%','%%');
If it's just text your printing, this'll be fine.
Minimal working example:
str = '2 & 3 & 10092 & 10763 & 103390 & 2797 & 2929 & 3008 & 5\% & 8\% \\'
str = strrep(str,'\','\\');
str = strrep(str,'%','%%');
f=fopen('testing123.txt','w');
fprintf(f,str);
fclose(f);
and the file reads:
2 & 3 & 10092 & 10763 & 103390 & 2797 & 2929 & 3008 & 5\% & 8\% \\
OR as Ben A. suggests, use fwrite:
fwrite(f,str)
and I think
fprintf(f,'%s',str)
will also do the trick, and it's best to also include a newline:
fprintf(f,'%s\n',str)