How to print negative numbers within a parenthesis with spreadtab in LaTex - format

I am trying to produce financial statements with latex. An important convention of financial statements is that negative numbers are not presented with a negative sign, rather wrapped in parentheses, like this:
-100 -> (100)
The minimum necessary recreation of my issue is as follows:
\documentclass{report}
\usepackage{tabularx}
\usepackage{spreadtab}
\usepackage{numprint}
\npthousandsep{,}
\begin{document}
\begin{center}
\STautoround{0}
\begin{spreadtab}{{tabularx}{\linewidth}{XN{7}{0}N{7}{0}}}
#\multicolumn{3}{c}{\uppercase{Municipal Government}}\\
#\multicolumn{3}{c}{Statement of Net Position}\\
#\multicolumn{3}{c}{December 31, 2019}\\
&& \\
#\multicolumn{1}{c}{\uppercase{Assets}} & #\multicolumn{1}{c}{2019} & #\multicolumn{1}{c}{2018}\\
#\multicolumn{1}{c}{Current Assets}&&\\
# Cash & 12345 & 54321\\
# Receivables:&&\\
# \hspace{0.25in}Sewer Fees: & 12345 & 54321\\ \cline{2-3}
#\multicolumn{1}{r}{Total Current Assets} & sum(b7:[0,-1]) & sum(c7:[0,-1])\\ % r10
#\multicolumn{1}{c}{\uppercase{Fixed Assets}}&&\\
# Land & 12345 & 54321\\
# Garage & 99247 & 54321\\
# Equipment & 12345 & 54321\\
# Lagoon and Related & 12345 & 54321\\ \cline{2-3}
#\multicolumn{1}{r}{Total Fixed Assets} & sum(b12:[0,-1]) & sum(c12:[0,-1])\\ \cline{2-3} % r15
# Accumulated Depreciation & -12345 & -54321\\ \cline{2-3}
#\multicolumn{1}{r}{Net Fixed Assets} & sum(b16:[0,-1]) & sum(c16:[0,-1])\\ \cline{2-3}
#\multicolumn{1}{r}{Total Assets} & b18+b10 & c18+c10\\ \cline{2-3} \cline{2-3}
\end{spreadtab}
\end{center}
\end{document}
Where rather than Accumulated Depreciation -12345 -54321, it reads Accumulated Depreciation (12345) (54321).
I have found scant little information about it online, and I'm not entirely certain it's possible to do.
If at all possible, I would like to retain the decimal alignment while adding the parentheses. But again, I'm not sure it's possible.
A solution, below, was shared on StackOverflow several years ago, but it concludes in several errors which I am unsure how to move beyond: primarily the compiler complaining about dozens of "missing" or "extra" brackets.
\makeatletter
\renewcommand\STprintnum[1]{\FPifneg{#1}(\#gobble#1)\else#1\fi}
\makeatother
Update: Per the below answer, using SIunitx permits wrapping negative numbers in brackets, but this breaks the decimal alignment. A minimum working example of this is as follows:
\documentclass{report}
\usepackage{tabularx}
\usepackage{siunitx}
\usepackage{spreadtab}
\sisetup{group-separator = {,}}
\sisetup{bracket-negative-numbers = true}
\begin{document}
\begin{spreadtab}{{tabularx}{\linewidth}{XS[table-format=7.1]S[table-format=7.1]}}
# Fixed Assets & 123456.1 & 135791.1\\
# {Accumulated Depreciation} &-100000.1 &-90000.1\\ \cline{2-3}
#\multicolumn{1}{r}{Net Fixed Assets} & sum(b1:[0,-1]) & sum(c1:[0,-1])\\ \cline{2-3}
\end{spreadtab}
\end{document}
In the above example, the negative numbers are now offset in their alignment by the left and right parenthesis, so they cease to line up with the positive numbers.

Related

Write a partitioned matrix in rmarkdown

I am trying to insert vertical and horizontal lines inside a matrix to divide it into 4 sections. I would like my matrix to look matrix 4.7 in Matrix Population Models by Dr. Caswell.
Please see my try below. How do I improve the code? Thanks a lot in advance.
$$A_{m,4} =
\begin{pmatrix}
a_{1,1} & a_{1,2} | & a_{1,3} & a_{1,n} \\
a_{2,1} & a_{2,2} | & a_{2,3} & a_{2,4} \\
----- | ----\\
a_{m,1} & a_{m,2} & a_{m,3} & a_{m,4}
\end{pmatrix}$$
You can use the following latex code in your RMD file:
$$A_{m,4} =
\left(
\begin{array}{cc|cc}
a_{1,1} & a_{1,2} & a_{1,3} & a_{1,n} \\
a_{2,1} & a_{2,2} & a_{2,3} & a_{2,4} \\
\hline
a_{m,1} & a_{m,2} & a_{m,3} & a_{m,4}
\end{array} \right)$$
The result:

Latex: TeXMaker does not compile - several unsolved errors

I am working on a protocol using TeXMaker. I switched from Eclipse+Texlipse to Texmaker and what compiled successfully before, does not compile anymore.
I have a main.tex file, which contains the structure of my protocol. I have several tex-files as inputs and a design.sty, which provides my design. I want to compile and create the PDF-protocol.
When I try to execute the following code in TeXMaker (the main.tex):
\documentclass[11pt,a4paper,oneside,listof=totoc, bibliography=totoc
version=first]{scrreprt}
\usepackage{design}
\begin{document}
\pagenumbering{arabic}
% cover
\input{./cover.tex}
% introduction
\newpage
\chapter{Introduction}
\section{Synmikro}
\input{./synmicro.tex}
\section{Genetic Switches}
\input{./switches.tex}
\section{ECFs}
\input{./ECF.tex}
\section{Sinorhizobium Meliloti}
\input{./meliloti.tex}
\newpage
\section{Laboratory Internship}
\input{./internship.tex}
\section{Bioinformatics}
\input{./bioinfo.tex}
% materials and methods
\newpage
\chapter{Material and Methods}
\section{Used strains}
\input{./MMexoECFs.tex}
\section{Cultivation conditions}
\input{./MMcultivation.tex}
\section{RNA preparation}
\input{./MMrNAprep.tex}
\section{Quality control of total RNA}
\input{./MMtotalRNAQC.tex}
%\section{Quality control}
% \subsection{PCR and Agarose gel}
% \input{./MMnormPCR.tex}
%\subsection{RNA purity and integrity control}
% \input{./MMbioanalyzer.tex}
\section{qRT-PCR}
\input{./MMqRTPCR.tex}
%\section{QBit}
% \input{./MMqbit.tex}
\section{Bioinformatics}
\input{./MMbioinfo.tex}
\subsection{Non-restrictive approach}
\input{./MMnonRestrictive.tex}
\subsection{Levenshtein distance}
\input{./MMlev2.tex}
\subsection{Feature Search}
\input{./MMfeatureSearch.tex}
%\subsection{Position Specific Scoring Matrices}
% \input{./MMpssm.tex}
% results
\newpage
\chapter{Results}
%\section{Agarose Gel}
% \input{./Ragarose.tex}
\section{Nanodrop and Bioanalyzer}
\input{./Rbioanalyzer.tex}
%\section{Qbit}
% \input{./Rqubit.tex}
\newpage
\section{Real-Time PCR}
\input{./RRTpCR.tex}
\newpage
\section{Bioinformatics}
\input{./Rbioinfo.tex}
% discussion
\end{document}
TeXMaker gives me several errors for main.tex. They are:
Line 47: File ended while scanning use of \caption#xdblarg
Line 79: !Latex Error: \begin{figure} on input line 7 ended by \end{document}
Line 79: !You can't use '\end’ in internal vertical mode
Line 79: !Latex Error: \begin{figure} on input line 7 ended by \end{document}
! Missing } inserted
Line 1: ! Emergency stop. <*> main.tex ***(job aborted, no legal \end found)
Line 47 is "\input{./MMqRTPCR.tex}
Line 79 is "\end{document}"
I am honestly confused. TeXMaker's error description is about missing braces. Am I screen-blind? I checked the braces 3 times and cannot figure out, what I missed. So, I am guessing, I missed something crucial about Latex.
Thanks for any help!
UPDATE:
In the input file "MMqRTPCR.tex", I out-commented a figure and all errors are gone. Here is the content of the file.
TEXTEXTEXT
%\begin{figure}[H]
%\centering
% \includegraphics[scale=0.6,natwidth=764,natheight=218]%{deltaDeltaCorrectedFormula.png}
% \caption{mycaption}
%\label{deltaDelta}
%\end{figure}
TEXTEXTEXT
\begin{table}[!h]
\centering
\caption{Primer sequences and targets}
\label{table1}
\begin{tabular}{|l|l|l|ll}
\cline{1-3}
Primer Sequence & Target & Direction \\ \cline{1-3}
AACATGTGCCGGTTGATAG & ECF20_992 & forward \\ \cline{1-3}
GCTGCTTCGGTATTGCTCA & ECF20_992 & reverse \\ \cline{1-3}
TCGTACCATTGAAAGCCTG & ECF02_2817 & forward \\ \cline{1-3}
ATCAATGGCTTCACGTGCA & ECF02_2817 & reverse \\ \cline{1-3}
TTCAAGAAACCATGGCCAC & ECF11_987 & forward \\ \cline{1-3}
GCTCGGCCAAATATCATCG & ECF11_987 & reverse \\ \cline{1-3}
\end{tabular}
\end{table}
TEXTEXTEXT
** UPDATE & SOLUTION**
The error was not in the main.tex itself, but in an input file. So, when TeXMaker tells you about missing bracers, jump to the line, where the error occured in the main.tex and check the bracers in the input file, which you see there.
So,
the error was a missing curly brace after all! Yet, it was not missing in the main.tex, but in the input file within the figure caption!
Thanks anybody, who's brain might have melted trying to find a solution to my problem. I hope this helps others, if they encounter the same error. :)

Eliminate matrix header in esttab (latex) or outtable output

I have a matrix of values (very non-standard summary statistics) that I want to pass from Stata to LaTeX. The command:
esttab matrix(matname) using $myfilename.tex, replace booktabs f
gives the matrix in LaTeX form but also gives the title of the matrix within the fragment. The same is true for:
outtable using myfilename, mat(matname) replace nobox
Currently, every time I rerun my Stata do file I have to go and edit myfilename.tex by hand.
Is there any way to non-manually remove the matrix name from the Stata to LaTeX output?
I tried using the option noheader, which works here:
matrix list matname, noheader
but doesn't seem to be active in esttab or outtable. It also occurred to me that if I could find a way to ask LaTex to just \input PART of the fragment file (lines 2 onward) that would work...
I think the nomtitles option will work. Here's reproducible example:
sysuse auto
reg price trunk headroom
matrix myMat = e(V)
esttab matrix(myMat) using temp.tex, replace booktabs f nomtitles
This produces the text (.tex) file below:
& trunk& headroom& \_cons\\
\midrule
trunk & 10557.96& -35339.31& -39464.18\\
headroom & -35339.31& 269901.5& -321726.7\\
\_cons & -39464.18& -321726.7& 1612951\\
Also, I used the following outtable command
outtable using "./temp", mat(myMat) replace center f(%9.2f) nobox
to produce this output:
% matrix: myMat file: ./temp.tex 10 Jun 2016 12:55:35
\begin{table}[htbp]
\begin{tabular}{lccc} \hline \hline
& trunk & headroom & cons \\ \hline
trunk & 10557.96 \\
headroom & -35339.31 & 269901.52 \\
cons & -39464.18 & -3.22e+05 & 1.61e+06 \\
\hline \hline \end{tabular}
\end{table}
While the matrix name is present in the output, it is commented out and so will not appear in the latex document.

Remove numbers at specific position in String VBScript

I have strings like these -
CRS|R|S||3.0|25|W||U||||0||ECN|211|MACROECONOMIC PRINCIPLES
CRS|R|S||3.0|25|F||U||||0||CIS|105|SURVEY COMPUTER INFO SYSTEMS
CRS|R|S||3.0|25|A||U||||12||CSR|207|AUTOMOBILE POLICY ADJUSTMENT
The format of these will always be like this.
I want to remove any numbers just before ECN, CIS or CSR above.
So after processing, my output should look like this -
CRS|R|S||3.0|25|W||U||||||ECN|211|MACROECONOMIC PRINCIPLES
CRS|R|S||3.0|25|F||U||||||CIS|105|SURVEY COMPUTER INFO SYSTEMS
CRS|R|S||3.0|25|A||U||||||CSR|207|AUTOMOBILE POLICY ADJUSTMENT
0 and 12 are removed from the strings above.
Please note - ECN, CIS or CSR are just for example. It can be anything. I want to remove the numbers before these 3 letters.
Please help me out !
Try Split on the |, emptying the value at the appropriate position, and then Join back together with the |.
Option Explicit
Dim input
Dim lines, ub, i, lineParts
Dim output
input = "CRS|R|S||3.0|25|W||U||||0||ECN|211|MACROECONOMIC PRINCIPLES" & vbCrLf & _
"CRS|R|S||3.0|25|F||U||||0||CIS|105|SURVEY COMPUTER INFO SYSTEMS" & vbCrLf & _
"CRS|R|S||3.0|25|A||U||||12||CSR|207|AUTOMOBILE POLICY ADJUSTMENT"
lines = Split(input, vbCrLf)
ub = UBound(lines)
For i = 0 To ub
lineParts = Split(lines(i), "|")
lineParts(12) = ""
lines(i) = Join(lineParts, "|")
Next
output = Join(lines, vbCrLf)

Rotated table in Latex appears at the end of the file

Any table I define with "sidewaystable" appears at the last page of created pdf file. How can I solve this?
\begin{sidewaystable}[h]
\caption{Blah Measurements}
\centering % centering table
\begin{tabular}{c c c c c c c c c c}
\hline\hline % inserting double-line
A & B & \multicolumn{3}{c}{C} & C Time + & D & \multicolumn{3}{c}{D Signal} \\
ID & ID & \multicolumn{3}{c}{Coordinates} & Time Diff. & Time & \multicolumn{3}{c}{Parameters} \\ [0.5ex]
\hline % inserts single-line
1 & 1 & 4415633.126837 & 482211.909079 & 939.450000 & 06:07:40 & 06:07:40 & -85 dBm & 6 dB & 5 dBm \\
\hline
\end{tabular}
\label{tab:combined}
\end{sidewaystable}
Have you tried the something like htbp for the placement of the float object?
\begin{sidewaystable}[htbp]
...
\end{sidewaystable}
Just use \clearpage \newpage before \begin{sidewaystable} and \clearpage after the \end{sidewaystable}..
It works without any floats like H, h!, htpb, etc.
you can try and use \begin{table}[h!] -- the ! will try and tell latex to force your table into the exact spot. I've had hit or miss results.
Also, with the float package, you can use a capital H \begin{table}[H] to keep your table from floating.

Resources