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

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}

Related

Multicolumns tables in LaTeX writing are not in correct order

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?

sporfire: calculate the avg per 15 minutes

I am a beginner for Spotfire. I have a problem about the average calculation per each 15 mins by calculated column. A sample table could be like this:
id time-stamp value
1 7/1/2016 12:01:01 AM 1.1
2 7/1/2016 12:05:03 AM 0.9
3 7/1/2016 12:08:04 AM 1.2
4 7/1/2016 12:09:06 AM 0.8
5 7/1/2016 12:12:09 AM 0.4
6 7/1/2016 12:14:10 AM 0.6
7 7/1/2016 12:15:12 AM 1.3
8 7/1/2016 12:18:04 AM 1.4
9 7/1/2016 12:21:06 AM 0.7
10 7/1/2016 12:24:09 AM 1.7
11 7/1/2016 12:31:10 AM 0.5
12 7/1/2016 12:39:12 AM 1.3
I want to calculate the avg value for each 15 mins, the table is already ordered by time.
the final table I want to have is:
time-stamp Avg
7/1/2016 12:00:00 AM 0.83333
7/1/2016 12:15:00 AM 1.275
7/1/2016 12:30:00 AM 0.9
for example, for the first number 0.83333 =(1.1+0.9+1.2+0.8+0.4+0.6)/6
it seems that I should identify an expression of the calculation for a new table, but how to calculate the avg. for each 15 mins. somebody could help me ?
thanks for your help :)
note: thanks for code #ksp585, but after this, i still have a small problem for it, the cross table just shows the times-stamp until 9:45 PM
# ZAWD - I have created a calculated column which groups the timestamp into 4 quarters for an hour. Used this column in the cross table below to calculate average time.
timestamp grouping expression (time_interval):
case
when (DatePart("minute",[time-stamp])>0) and (DatePart("minute",[time-stamp])<15) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":00" & ":00"
when (DatePart("minute",[time-stamp])=15) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":15" & ":00"
when (DatePart("minute",[time-stamp])>15) and (DatePart("minute",[time-stamp])<30) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":15" & ":00"
when (DatePart("minute",[time-stamp])=30) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":30" & ":00"
when (DatePart("minute",[time-stamp])>30) and (DatePart("minute",[time-stamp])<45) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":30" & ":00"
when (DatePart("minute",[time-stamp])=45) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":45" & ":00"
when (DatePart("minute",[time-stamp])>45) and (DatePart("minute",[time-stamp])<=60) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":45" & ":00"
when (DatePart("minute",[time-stamp])=0) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":00" & ":00"
else null end
Final Table:
Tested with a different datetime format:

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.

Using a for loop to access Command Prompt

I want to call a function Christian.exe to the command line to act of a series of files that are indexed as "reentrant_008.sif" (8 is an example number).
"Christian.exe reentrant_00" & num & ".sif reentrant_00" & num & ".pgm" 0 2000 is the text that needs to be fed into the command prompt for the program to execute (num is an arbitrary number)
There are approximately 400 files, so I want to create a vbs code that calls the command prompt for each file until all the files have been accessed so far this is my code:
For
Dim cmdpath
num = CStr(i)
Set wshShell = WScript.CreateObject ("WSCript.shell")
If i < 10 Then
cmdpath = "Christian.exe reentrant_00" & num & ".sif reentrant_00" & num & ".pgm" 0 2000
Else
If i < 100 Then
cmdpath = "Christian.exe reentrant_0" & num & ".sif reentrant_0" & num & ".pgm" 0 2000
Else
cmdpath = "Christian.exe reentrant_" & num & ".sif reentrant_" & num & ".pgm" 0 2000
End If
End If
wshshell.run cmdpath
Next
Problem is that a new command prompt is being called for each file, which is slowing down my computer. How do I ensure that only one command window that addresses all my files is called?
If you look at the documentation for Run you will see two option arguments [intWindowStyle], [bWaitOnReturn]. If you want your EXE to wait before proceeding on the script change your call to this
wshshell.run cmdpath, 0, True
Where 0 will hide the window and True will wait for the program to finish before proceeding in the script. Depending on your needs you could change the number or remove it.
wshshell.run cmdpath,, True
Since you tagged your question with both vbscript and powershell I'm adding a PowerShell solution:
foreach ($i in 1..400) {
$num = "{0:d3}" -f $i
& Christian.exe "reentrant_${num}.sif" "reentrant_${num}.pgm" 0 2000
}
& is the call operator. I recommend using it whenever you run external commands in PowerShell, because otherwise you'll be in for a surprise when you try to run a command from a variable for the first time:
$christian = "Christian.exe"
$christian ... # <-- throws an error, because $christian contains a
# string, which is NOT automagically interpreted
# as a command by PowerShell
& $christian ... # <-- works
-f is the formatting operator, that allows you to create formatted string output. Since your command lines only differ by the zero-padding of the input and output files it's better to build the file names with pre-padded number strings.
I recommend doing the pre-padding in VBScript as well:
For i = 1 To 400
num = Right("000" & i, 3)
cmdpath = "Christian.exe reentrant_" & num & ".sif reentrant_" & num & _
".pgm" 0 2000
wshshell.run cmdpath, 0, True
Next

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)