TransWikia.com

Losing alignment with fbox

TeX - LaTeX Asked by Pyrrhic Buddha on December 8, 2020

I am using this command to put a box around stuff.

newcommand{cfbox}[1]{%
{color{black}%
setlengthfboxsep{0pt}fbox{
    begin{varwidth}{dimexprcolumnwidth-2}
      leavevmode{color{black}#1}
    end{varwidth}
  }
}%
}

enter image description here

The problem is that each block gets a different alignment, I wanted all of them to be aligned with the first block.

Also, not the core of the question but if anyone also knows: How do I center the caption of the table back? After using the command the text went to the left… (it is not necessary to answer this though).

Here’s the example to run

documentclass{acmart}
usepackage[utf8]{inputenc}
usepackage{varwidth}
usepackage{tikz}

newcommand{cfbox}[1]{%
{setlengthfboxsep{0pt}fbox{
   begin{varwidth}{dimexprcolumnwidth-2}
       leavevmode{color{black}#1}
   end{varwidth}%
   }
}
}

begin{document}

cfbox{
cfbox{
section{Introduction}
}
cfbox{
If you are new to publishing with ACM, this document is a valuable
guide to the process of preparing your work for publication. If you
have published with ACM before, this document provides insight and
instruction into more recent changes to the article template.
}
}

cfbox{
begin{table}[H]   
caption{Frequency of Special Characters}  
label{tab:freq}
cfbox{
    begin{tabular}{ccl}
        toprule
        Non-English or Math&Frequency&Comments
        midrule
        O & 1 in 1,000& For Swedish names
        $pi$ & 1 in 5& Common in math
        $ & 4 in 5 & Used in business
        $Psi^2_1$ & 1 in 40,000& Unexplained usage
    bottomrule
    end{tabular}
}
end{table}
}

cfbox{
begin{table}[H]   
caption{Frequency of Special Characters}  
label{tab:freq}
cfbox{
    begin{tabular}{ccl}
        toprule
        Non-English or Math&Frequency&Comments
        midrule
        O & 1 in 1,000& For Swedish names
        $pi$ & 1 in 5& Common in math
        $ & 4 in 5 & Used in business
        $Psi^2_1$ & 1 in 40,000& Unexplained usage
        bottomrule
    end{tabular}
}
end{table}
}

end{document}

One Answer

I found the answer, having maketitle on the tex impacts the alignment of some specific cfbox. If you have maketitle, then between cfbox of table and section there shouldn't be a blank line, otherwise the alignment changes. On the other hand, if you don't have maketitle on the tex, then you need to have a blank line between cfbox of table and section, otherwise the alignmnent changes to the opposite direction. The comments said I should put % on the cfbox, but after putting % everywhere on the tex, there was no change.

I still don't know how to center the table description. This tex below shows the example running as expected when with maketitle.

documentclass[acmsmall, natbib=false, review]{acmart}

usepackage{varwidth}

copyrightyear{2018}
acmYear{2018}
acmDOI{10.1145/1122445.1122456}
acmConference[Woodstock '18]{Woodstock '18: ACM 
Symposium 
on Neural
Gaze Detection}{June 03--05, 2018}{Woodstock, NY}
acmBooktitle{Woodstock '18: ACM Symposium on Neural 
Gaze 
Detection,
June 03--05, 2018, Woodstock, NY}
acmPrice{15.00}
acmISBN{978-1-4503-XXXX-X/18/06}

newcommand{cfbox}[1]{%
{setlengthfboxsep{0pt}fbox{%
    begin{varwidth}{dimexprcolumnwidth}%
        {leavevmodecolor{black}#1}%
    end{varwidth}%
    }% 
}
}

begin{document}

title{Test}

maketitle



cfbox{

cfbox{
section{Introduction}
}

cfbox{
If you are new to publishing with ACM, this document is 
a valuable
guide to the process of preparing your work for 
publication. 
If you
have published with ACM before, this document provides 
insight and
instruction into more recent changes to the article 
template.
}

}

cfbox{
begin{table}[H]   
caption{Frequency of Special Characters}  
label{tab:freq}
cfbox{
begin{tabular}{ccl}
toprule
Non-English or Math&Frequency&Comments
midrule
O & 1 in 1,000& For Swedish names
$pi$ & 1 in 5& Common in math
$ & 4 in 5 & Used in business
$Psi^2_1$ & 1 in 40,000& Unexplained usage
bottomrule
end{tabular}
}
end{table}
}
cfbox{
cfbox{
section{Introduction}
}

cfbox{
If you are new to publishing with ACM, this document is 
a valuable
guide to the process of preparing your work for 
publication. 
If you
have published with ACM before, this document provides 
insight and
instruction into more recent changes to the article  
template.
}

}

cfbox{

cfbox{
section{Introduction}
}

cfbox{
If you are new to publishing with ACM, this document is 
a valuable
guide to the process of preparing your work for 
publication. 
If you
have published with ACM before, this document provides 
insight and
instruction into more recent changes to the article 
template.
}

}

cfbox{

cfbox{
section{Introduction}
}

cfbox{
If you are new to publishing with ACM, this document is 
a 
valuable
guide to the process of preparing your work for 
publication. 
If you
have published with ACM before, this document provides 
insight and
instruction into more recent changes to the article 
template.
}

}

cfbox{

cfbox{
section{Introduction}
}

cfbox{
If you are new to publishing with ACM, this document is 
a 
valuable
guide to the process of preparing your work for 
publication. 
If you
have published with ACM before, this document provides 
insight and
instruction into more recent changes to the article             
template.
}

}


end{document}
endinput

Answered by Pyrrhic Buddha on December 8, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP