Using \directlua command inside tikzpicture (pgf-pie) causes image not to render:
\documentclass[margin=5mm,preview]{standalone}
\usepackage{pgf-pie}
\begin{document}
\begin{tikzpicture} % works
\pie[radius=2, rotate=100, sum=auto]
{
3/test , 2/two , 3/three , 4/four
}
\end{tikzpicture}
\begin{tikzpicture} % does not work
\pie[radius=2, rotate=100, sum=auto]
{
\directlua{tex.sprint("3/test , 2/two , 3/three , 4/four")}
}
\end{tikzpicture}
\end{document}
The result can be view here
How gets \directlua expanded? And what do I need to change to create tikzpicture pie charts with variables from lua?
Related
I'm new to knitr and Latex stuff, so this may be a very naive question, but I failed to find a correct answer.
I'm doing empirical research that sometimes, we need to add headnotes as instruction for a complex table.
Below is the code I'm currently using (in a file named test.Rnw).
\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{authblk}
\usepackage{float}
\usepackage{array}
\usepackage{booktabs}
\usepackage{mathptmx}
\usepackage{pdflscape}
\usepackage{fullpage}
\usepackage{cite}
\usepackage{color}
% packages intend to rotate table
\usepackage[graphicx]{realboxes}
\usepackage{adjustbox}
\usepackage{rotating}
\usepackage[top = 0.5in, bottom = 0.5in, left = 0.5in, right = 0.5in]{geometry}
\begin{document}
\section{TEST CODE}
<<Table_Test Test Table, echo=FALSE, results="asis", warning=FALSE, message=FALSE>>=
set.seed(138744)
df_1 <- data.frame("id" = c('a', 'a', 'a', 'b','b','b'),
'time' = c(1991,1991,1991, 2001,2003,2004),
'value' = c('x', 'y','x','z','w','u'))
table_instruction <-"This is only here to test whether the text is too long. This is only here to test whether the text is too long"
print(xtable(df_1,# first zero "represents" row numbers which we skip later
# align and put a vertical line (first "l" again represents column of row numbers)
align = paste0("ll", paste0(rep("c", dim(df_1)[2]-1), collapse = "")),
caption = "Test Table",
label='test-tab'),
floating = TRUE,
size="\\fontsize{8pt}{10pt}\\selectfont", #Change size; useful for bigger tables "normalsize" "footnotesize"
include.rownames = FALSE, #Don't print rownames
include.colnames = TRUE, #We create them ourselves
caption.placement = "top", #"top", NULL
hline.after=NULL, #We don't need hline; we use booktabs
# floating.environment = 'sidewaystable',# to rotate the table
# whether \begin{Table} should be created (TRUE) or not (FALSE)
sanitize.text.function = force, # Important to treat content of first column as latex function
add.to.row = list(pos = list(-1, -1, 0, nrow(df_1)),
command = c(paste0("\\toprule \n"),# NEW row
paste0("\\multicolumn{", dim(df_1)[2],"}{#{}l}{", table_instruction,"} \\\\" ,
"\\cmidrule(l){1-", dim(df_1)[2], "}"),
paste0("\\cmidrule(l){1-", dim(df_1)[2], "} \n"),
paste0("\\bottomrule \n \\multicolumn{",dim(df_1)[2],"}{l}",
"",paste("{\\scriptsize{", "***$p$< .001, **$p$< .01, *$p$< .05","}}",sep = " "),"\\\\"))
)
)
#
\end{document}
Then I render the above code using the code below:
rm(list=ls())
library("knitr")
knit2pdf('test.Rnw')
It works successfully, the problem is that the headnotes (right above the header row) is not self-contained to the table's width. Instead, it stretches the table way too wide.
Any suggestion on how to make the long headnotes, no matter how long, to have consistent width with the table?
Can we have use hdashline with starting and ending markers? Something like
<---------->
One possibility is to use tikz:
\documentclass{article}
\usepackage{tikz}
\begin{document}
some text
\noindent\tikz{\draw[<->,dashed] (0,0) -- (\textwidth-0.4pt,0);}
some text
\end{document}
If you need this in a table, you can use the nicematrix package (inspired by this answer https://tex.stackexchange.com/a/635224/36296 )
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
\NiceMatrixOptions
{
custom-line =
{
command = arrowrule ,
tikz = { dashed, <-> }
}
}
\begin{NiceTabular}{XX}
some & text\\
\arrowrule
some & text\\
\end{NiceTabular}
\end{document}
I am trying to create three environments that are beside one another and do not fill the entire page as seen in the attached image. Within each environment, I am trying to add the cvref function, attached is the necessary cls code.
test.cls
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\#ifl#t#r\fmtversion{2018/04/01}{\UseRawInputEncoding}{}
\ProvidesClass{altacv}[2018/07/27 AltaCV v1.1.4, yet another alternative class for a résumé/curriculum vitae.]
\newif\if#academicons
\DeclareOption{academicons}{\#academiconstrue}
%% v1.1.3: Choice of round/square photo
\newif\if#normalphoto
\DeclareOption{normalphoto}{\#normalphototrue}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{extarticle}}
\ProcessOptions\relax
\LoadClass{extarticle}
\RequirePackage[margin=2cm]{geometry}
\RequirePackage{fontawesome}
%% v1.1: Optionally load academicons
\if#academicons
%% Patch to make academicons compilable with XeLaTeX
\ExplSyntaxOn
\msg_redirect_name:nnn { fontspec } { font-not-found } { none }
\ExplSyntaxOff
\RequirePackage{academicons}
\newfontfamily{\AI}{academicons.ttf}
\fi
\RequirePackage{xcolor}
\colorlet{accent}{blue!70!black}
\colorlet{heading}{black}
\colorlet{emphasis}{black}
\colorlet{body}{black!80!white}
\newcommand{\itemmarker}{{\small\textbullet}}
\newcommand{\ratingmarker}{\faCircle}
\RequirePackage{tikz}
\usetikzlibrary{arrows}
\RequirePackage[skins]{tcolorbox}
\RequirePackage{enumitem}
\setlist{leftmargin=*,labelsep=0.5em,nosep,itemsep=0.25\baselineskip,after=\vskip0.25\baselineskip}
\setlist[itemize]{label=\itemmarker}
\RequirePackage{graphicx}
\RequirePackage{etoolbox}
\RequirePackage{dashrule}
\RequirePackage{multirow,tabularx}
\RequirePackage{changepage}
% \RequirePackage{marginfix}
\setlength{\parindent}{0pt}
\newcommand{\divider}{\textcolor{body!30}{\hdashrule{\linewidth}{0.6pt}{0.5ex}}\medskip}
\newenvironment{fullwidth}{%
\begin{adjustwidth}{}{\dimexpr-\marginparwidth-\marginparsep\relax}}
{\end{adjustwidth}}
\newcommand{\emailsymbol}{\faAt}
\newcommand{\phonesymbol}{\faPhone}
\newcommand{\homepagesymbol}{\faChain}
\newcommand{\locationsymbol}{\faMapMarker}
\newcommand{\linkedinsymbol}{\faLinkedin}
\newcommand{\twittersymbol}{\faTwitter}
\newcommand{\githubsymbol}{\faGithub}
\newcommand{\orcidsymbol}{\aiOrcid}
\newcommand{\mailsymbol}{\faEnvelope}
\newcommand{\printinfo}[2]{\mbox{\textcolor{accent}{\normalfont #1}\hspace{0.5em}#2\hspace{2em}}}
\newcommand{\weblinks}[3]{\mbox{\textcolor{accent}{\normalfont #1}\hspace{0.5em}{\href{#2}{#3}}\hspace{2em}}}
\newcommand{\name}[1]{\def\#name{#1}}
\newcommand{\tagline}[1]{\def\#tagline{#1}}
\newcommand{\photo}[2]{\def\#photo{#2}\def\#photodiameter{#1}}
\newcommand{\email}[2]{\weblinks{\emailsymbol}{#1}{#2}}
\newcommand{\mailaddress}[1]{\printinfo{\mailsymbol}{#1}}
\newcommand{\phone}[1]{\printinfo{\phonesymbol}{#1}}
\newcommand{\homepage}[2]{\weblinks{\homepagesymbol}{#1}{#2}}
\newcommand{\twitter}[1]{\printinfo{\twittersymbol}{#1}}
\newcommand{\linkedin}[2]{\weblinks{\linkedinsymbol}{#1}{#2}}
\newcommand{\github}[2]{\weblinks{\githubsymbol}{#1}{#2}}
\newcommand{\orcid}[1]{\printinfo{\orcidsymbol}{#1}}
\newcommand{\location}[1]{\printinfo{\locationsymbol}{#1}}
\newcommand{\cvsection}[2][]{%
\bigskip%
\ifstrequal{#1}{}{}{\marginpar{\vspace*{\dimexpr1pt-\baselineskip}\raggedright\input{#1}}}%
{\color{heading}\LARGE\bfseries\MakeUppercase{#2}}\\[-1ex]%
{\color{heading}\rule{\linewidth}{2pt}\par}\medskip
}
\newcommand{\cvref}[4]{%
\smallskip
\textcolor{emphasis}{\textbf{#1}}\par
\smallskip\normalsize
\ifstrequal{#2}{}{}{
\textbf{\color{accent}#2}\par
\smallskip}
\begin{description}[font=\color{accent},style=multiline,leftmargin=1.25em]
\item[\small\normalfont\mailsymbol] #3
\item[\small\normalfont\phonesymbol] #4
\end{description}
\medskip
% \medskip
}
\newenvironment{cvcolumn}[1]{\begin{minipage}[t]{#1}\raggedright}{\end{minipage}}
\RequirePackage[backend=biber,style=authoryear,sorting=ydnt]{biblatex}
%% For removing numbering entirely when using a numeric style
% \setlength{\bibhang}{1em}
% \DeclareFieldFormat{labelnumberwidth}{\makebox[\bibhang][l]{\itemmarker}}
% \setlength{\biblabelsep}{0pt}
\defbibheading{pubtype}{\cvsubsection{#1}}
\renewcommand{\bibsetup}{\vspace*{-\baselineskip}}
\AtEveryBibitem{\makebox[\bibhang][l]{\itemmarker}}
\setlength{\bibitemsep}{0.25\baselineskip}
% v1.1.2: make it easier to add a sidebar aligned with top of next page
\RequirePackage{afterpage}
\newcommand{\addsidebar}[2][]{\marginpar{%
\ifstrequal{#1}{}{}{\vspace*{#1}}%
\input{#2}}%
}
\newcommand{\addnextpagesidebar}[2][]{\afterpage{\addsidebar[#1]{#2}}}
\AtBeginDocument{%
\pagestyle{empty}
\color{body}
\raggedright
}
It is called in the following snippet:
test.tex
\PassOptionsToPackage{dvipsnames}{xcolor}
\documentclass[10pt,letterpaper]{altacv}
\geometry{left=1cm,right=9cm,marginparwidth=6.8cm,marginparsep=1.2cm,top=1.25cm,bottom=1.25cm,footskip=2\baselineskip}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[default]{lato}
\definecolor{Mulberry}{HTML}{72243D}
\definecolor{SlateGrey}{HTML}{2E2E2E}
\definecolor{LightGrey}{HTML}{666666}
\colorlet{heading}{Sepia}
\colorlet{accent}{Mulberry}
\colorlet{emphasis}{SlateGrey}
\colorlet{body}{LightGrey}
\renewcommand{\itemmarker}{{\small\textbullet}}
\renewcommand{\ratingmarker}{\faCircle}
\usepackage[hidelinks]{hyperref}
\begin{document}
\begin{fullwidth}
\cvsection{References}
\begin{minipage}[t]{0.5\textwidth}
\begin{flushleft}
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{flushleft}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
\begin{center}
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{center}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
\begin{flushright}
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{flushright}
\end{minipage}
\end{fullwidth}
\medskip
\end{document}
Any guidance would be greatly appreciated. I tried a tabular environment, but it won't let me use the cvref function within the cells.
Using minipages, I get the following result:
your fullwidth environment does not adjust the \textwidth. However you can use .33\linewidth to automatically get the width of the minipages
the cvref macro internally used a description, that's why it does not obey your attempts to center or left align. You can use the following redefinition to get a similar result, which will obey your alignment:
\PassOptionsToPackage{dvipsnames}{xcolor}
\documentclass[10pt,letterpaper]{test}
\geometry{left=1cm,right=9cm,marginparwidth=6.8cm,marginparsep=1.2cm,top=1.25cm,bottom=1.25cm,footskip=2\baselineskip}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[default]{lato}
\definecolor{Mulberry}{HTML}{72243D}
\definecolor{SlateGrey}{HTML}{2E2E2E}
\definecolor{LightGrey}{HTML}{666666}
\colorlet{heading}{Sepia}
\colorlet{accent}{Mulberry}
\colorlet{emphasis}{SlateGrey}
\colorlet{body}{LightGrey}
\renewcommand{\itemmarker}{{\small\textbullet}}
\renewcommand{\ratingmarker}{\faCircle}
\usepackage[hidelinks]{hyperref}
\renewcommand{\cvref}[4]{%
\smallskip
\textcolor{emphasis}{\textbf{#1}}\par
\smallskip\normalsize
\ifstrequal{#2}{}{}{
\textbf{\color{accent}#2}\par
\smallskip}
% \begin{description}[font=\color{accent},style=multiline,leftmargin=1.25em]
{\color{accent}\small\normalfont\mailsymbol} #3\par
{\color{accent}\small\normalfont\phonesymbol} #4\par
% \end{description}
\medskip
% \medskip
}
\begin{document}
\begin{fullwidth}
\cvsection{References}
\begin{minipage}[t]{0.3\linewidth}
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{minipage}
\begin{minipage}[t]{0.3\linewidth}
\centering
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{minipage}
\begin{minipage}[t]{0.3\linewidth}
\raggedleft
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{minipage}
\end{fullwidth}
\end{document}
I am trying to create a new environment where I can add different rows, where each row contains a short makro:
\documentclass{report}
\newenvironment{test}{%
\begin{tabular}{|p{2cm}|p{2cm}|}
}
{
\end{tabular}
}
% function to add rows
\newcommand\row{%
\def\type{4}
cell 1: \type &
cell 2: \type \\
}
\begin{document}
\begin{test}
\row
\end{test}
\end{document}
Unfortunately, this gives an "undefined control sequence" error and the makro is not available in the second column:
How can makros be available in the whole row?
I finally found a solution following https://tex.stackexchange.com/questions/195747/using-in-macro-abstracting-a-tabulars-row. It's as simple as replacing def with gdef (minding that the definitions are now global):
\documentclass{report}
\newenvironment{test}{%
\begin{tabular}{|p{2cm}|p{2cm}|}
}
{
\end{tabular}
}
% function to add rows
\newcommand\row{%
\gdef\type{4}
cell 1: \type &
cell 2: \type \\
}
\begin{document}
\begin{test}
\row
\end{test}
\end{document}
I am making some changes in Warsaw theme. I want to increase the height of the frametitle. I have used the following code, because I did not want the navigation part from the the headline. Now I need to increase the height of the frame title without increasing the font size. Please see the commands I used:
\setbeamertemplate{headline}{%
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=0 ex,dp=0ex]{palette quaternary}%
\end{beamercolorbox}%
}
}
You could adjust the frametitle template. I marked the line to change with % <-
\documentclass{beamer}
\usetheme{Warsaw}
\setbeamertemplate{headline}{}
\makeatletter
\setbeamertemplate{frametitle}{%
\nointerlineskip%
\vskip-2pt%
\hbox{\leavevmode
\advance\beamer#leftmargin by -12bp%
\advance\beamer#rightmargin by -12bp%
\beamer#tempdim=\textwidth%
\advance\beamer#tempdim by \beamer#leftmargin%
\advance\beamer#tempdim by \beamer#rightmargin%
\hskip-\Gm#lmargin\hbox{%
\setbox\beamer#tempbox=\hbox{\begin{minipage}[b]{\paperwidth}%
\vbox{}\vskip-.75ex%
\vspace{2cm}% <- change here to whatever you want
\leftskip0.3cm%
\rightskip0.3cm plus1fil\leavevmode
\usebeamercolor[fg]{frametitle}\usebeamerfont{frametitle}\strut\insertframetitle\strut\par%
\ifx\insertframesubtitle\#empty\else%
{\usebeamerfont*{framesubtitle}{\usebeamercolor[fg]{framesubtitle}\insertframesubtitle}\strut\par}%
\fi%
\nointerlineskip
\vbox{}%
\end{minipage}}%
\beamer#tempdim=\ht\beamer#tempbox%
\advance\beamer#tempdim by 2pt%
\begin{pgfpicture}{0pt}{0pt}{\paperwidth}{\beamer#tempdim}
\usebeamercolor{frametitle right}
\pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer#tempdim}}
\pgfusepath{clip}
\pgftext[left,base]{\pgfuseshading{beamer#frametitleshade}}
\end{pgfpicture}
\hskip-\paperwidth%
\box\beamer#tempbox%
}%
\hskip-\Gm#rmargin%
}%
\nointerlineskip
\vskip-0.2pt
\hbox to\textwidth{\hskip-\Gm#lmargin\pgfuseshading{beamer#topshade}\hskip-\Gm#rmargin}
\vskip-2pt
}
\makeatother
\begin{document}
\section{title}
\begin{frame}
\frametitle{title}
abc
\end{frame}
\end{document}