Hot answers tagged

31

This answer has four five six four routines: the last update: leaner code 6, as I understand better my hacky use of \pdfescapestring and could remove some superfluous extras (if they had been really needed, these extras would not have been enough anyhow). the very last update: improved sub-routine for merging in code 6 bringing at least a 2x speed ...


29

This answer consists of three parts: a solution with manual adjustment of the vertical spacing, a solution with a modified \arraystretch that automatically centers the brackets around the matrix properly (unlike the original \arraystretch!), an explanation of the ugly default spacing. The easy answer You have two issues here: The spacing is ugly ...


29

I ran your code but it appeared to be very slow, I suspect from all the \pgfmathtruncatemacro. But here we can do all calculations with \numexpr easily. This code is based on the TeX primitives \ifnum, \ifcase and \csname..\endcsname. I have used \foreach loops in the first two code samples as I wanted to stay close to your original framework. In the third ...


28

It's been a while since I played with NumPy, but I used to call the numpy.savetxt function to export my data as a .csv format: import numpy A = numpy.random.randn(4,4) numpy.savetxt("mydata.csv", A) The sample file mydata.csv was generated accordingly: 1.058690791897618361e-01 4.236767150069661314e-01 -9.871862191240249329e-02 1.896410657805123634e+00 ...


27

As @whlt3 said it is required if you intend to have a final horizontal line \hline or a partical line via \cline{...} or if you want to have some extra space blow that line produced via the optional argument of \\. If not then it is completely optional. I would however suggest to use \\ on all lines as that allows you to easily add or reorder rows in your ...


23

You can stick some \struts in there (the height+depth of a paren): \documentclass{article} \usepackage{mathtools} \begin{document} \[ \begin{bmatrix} \dfrac{\strut\partial f}{\strut\partial x} \\ \dfrac{\strut\partial f}{\strut\partial y} \end{bmatrix} \] \end{document}


23

To answer the specific question you are asking, here is a complete minimal example. \documentclass{standalone} \usepackage{pgfmath} \begin{document} \def\names{{"Katie","Frank","Laura","Joe"}}% \pgfmathparse{\names[2]}\pgfmathresult \end{document} So, you need to use the pgfmath parser to do the job through \pgfmathparse and then use the result of the ...


22

The most straightforward way of putting something in a framed box is the \fbox command. \documentclass{article} \begin{document} \newcommand{\sep}{\hspace*{.5em}} \noindent $\fbox{5} \sep \fbox{2} \sep \fbox{7} \sep \fbox{-5} \sep \fbox{16} \sep \fbox{12}$ \end{document} Now that does not look very nice, the boxes are differently sized, depending ...


22

\documentclass{article} \usepackage{amsmath} \begin{document} % ... \[\arraycolsep=1.4pt\def\arraystretch{2.2} \begin{array}{ccccc} x(1) & = & \dfrac{x(0)}{1} & = & x(0)\\ x(2) & = & \dfrac{x(1)}{2} & = & \dfrac{x(0)}{2}\\ x(3) & = & \dfrac{x(2)}{3} & = & \dfrac{x(0)}{2.3}\\ x(4) & = & \dfrac{x(3)}{4} ...


19

Just for fun (but perhaps it can be useful to anyone), there is my Lua solution: Main TeX file \documentclass{article} \usepackage{pgffor} \usepackage{xcolor} \usepackage{courier} % Courier has bold series, while cm doesnt \usepackage[active,tightpage]{preview}\PreviewEnvironment{tabular} % Load lua program, and define macros for accessing its functions ...


18

The blkarray package allows to do complex border matrix with relatively simple code: \documentclass{article} \usepackage{blkarray} \usepackage{multirow} \begin{document} \[ \begin{blockarray}{cc|cccc|cccc} & 1\dots 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 \\ \begin{block}{c(c|cccc|cccc@{\hspace*{5pt}})} ...


18

Working from [SciPy-User] 2d array to Latex: $ python Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> a=numpy.zeros((2,2)) >>> print " \\\\\n".join([" & ".join(map(str,line)) for line in a]) 0.0 & 0.0 \\ 0.0 & 0.0 >>> Add on tabular, table, ...


17

I have modified the sudoku.sty for you and here are the contents of the 4x4 sudoku44.sty file. Save the contents below in the name sudoku44.sty and keep it in the same directory as your .tex file. (Alternatively put the file in C:\Program Files\MiKTeX 2.9\tex\latex\sudoku\ and run a refresh file name data base if on windows.) %% %% This is file ...


16

You don't need to modify sudoku.sty, just to use its infrastructure: we can use the macros as modified by Harish Kumar, but changing their names. In this way you can input both sudoku and shidoku puzzles using a similar syntax. \documentclass{article} \usepackage{sudoku} \makeatletter \newcommand*\@shidoku@grid{ \linethickness{\sudokuthinline}% ...


16

After getting these two answers I'd like to publish my solution also. After seeing jfbu's answer I was a bit intimidated and I went the luatex way. The code is probably not efficient, but it can produce an animated PDF – unfortunately this feature only works in Adobe Reader – or pages with the different evolution phases. Also this code only works with n×n ...


16

Here is a sans-tikz approach to typesetting an array. The etoolbox package provides \docsvlist that processes a comma separated value (CSV) list using the element-wise generic \do command that takes one argument. By redefining \do, you can modify the operation performed on/to each element. In the following minimal working example, the ...


16

You could insert \displaystyle into the column definition, such as \begin{array}{*3{>{\displaystyle}c}p{5cm}} Here I used syntax provided by the array package: >{...} can insert commands before the array element *n{...} repeats a column definition n times So in the example we get 3 columns, where all cells have \displaystyle, and 1 paragraph ...


16

It is also relatively easy to solve using just TikZ: \documentclass{article} \usepackage{tikz} \newcounter{arraycard} \def\arrayLength#1{% \setcounter{arraycard}{0}% \foreach \x in #1{% \stepcounter{arraycard}% }% \the\value{arraycard}% } \begin{document} \noindent The length of $\{1,2,3\}$ is \arrayLength{{1,2,3}}.\\ And the length of ...


16

In the cvs version of pgf/tikz or in the version available for texlive at tlcontrib there is an experimental undocumented dim function in pgfmath defined as \makeatletter % dim function: return dimension of an array % dim({1,2,3}) return 3 % dim({{1,2,3},{4,5,6}}) return 2 \pgfmathdeclarefunction{dim}{1}{% \begingroup \pgfmath@count=0\relax ...


16

On either side of each column of an array (or tabular) latex adds \arraycolsep) (or \tabcolsep for tabular) of whitespace, so normally there is 2\arraycolsep space between the columns. If you go @{hello} then instead of adding space between the columns latex inserts hello in each row. Sometimes you see forms such as r@{\mbox{--}}l which would make 2 & ...


14

A possibility using TikZ and matrix of math nodes (from the matrix library) to build the natrices; the braces for the dimensions were built using a brace decoration from the decorations.pathreplacing library: \documentclass{article} \usepackage{tikz} \usepackage{geometry} \usetikzlibrary{matrix,positioning,decorations.pathreplacing} \begin{document} ...


14

This answer may be more generic than specifically relating to TikZ/PGF. (La)TeX is a macro-based language, so it does not work as expected compared to other languages when dealing with "arrays". For example, while \names[2] should yield Laura where \def\names{Katie, Frank, Laura, Joe} (indexing from 0), (La)TeX considers [2] to have no connection to ...


14

Basic Example: Here is an example of one way to reproduce the Division Algorithm from Page 4 of Grobner Bases and their Applications by Kaitlyn Moran using an array. Notes: multirow was used to center the \sqrt{xy^2 + 1} term in between the two rows. \multicolumn{1}{c}{<text>} was used to center content within a cell Extended Example For the ...


14

Here's a possible solution using a tabular: \documentclass{article} \usepackage{array} \newcolumntype{P}{% >{\rule[-0.6cm]{0pt}{1.5cm}\centering$}p{1cm}<{$}} \begin{document} \noindent\begin{tabular}{!{\vrule width 2pt}P|P!{\vrule width 2pt}P|P!{\vrule width 2pt}} \noalign{\hrule height 2pt} a & b & c & d \tabularnewline \hline a & ...


13

\documentclass{article} \usepackage{array} \newcount\tc \makeatletter \def\x@multispan#1{% \begingroup \@multicnt#1\relax \def\xtmp{}% \let\sp@n\relax \loop\ifnum\@multicnt>\@ne \xdef\xtmp{\xtmp\span\omit}\advance\@multicnt\m@ne\repeat \endgroup \xtmp} \protected\def\>#1{% \ifnum#1>\numexpr\tc+\@ne\relax ...


13

The spacing is all wrong if you use an array, the AMS alignments provide alignment whilst preserving operator spacing: \documentclass{article} \usepackage{amsmath} \begin{document} \begin{equation} \begin{array}{ccl} a + b + c & = & d \\ e + f & = & g \\ h & = & i \end{array} \end{equation} ...


13

You can use a simple tabular and colortbl: \documentclass{article} \usepackage{colortbl} \usepackage{amsmath,amssymb} \begin{document} \begin{tabular}{c@{\,}l@{}} & $p$ \\ \arrayrulecolor{blue} & $p \to q$ \\\cline{2-2} $\therefore$ & $q$ \\ \end{tabular} \end{document} You can change the color of ...


13

Rather than fiddling with \hline, it's better in your case to provide "struts": either a "top strut," which provides vertical spacing above the line where it's placed, or a "bottom strut," which provides vertical spacing below the line where it's placed. This idea is not original to me -- it goes back (at least) to an article published by Claudio Beccari in ...


13

You can build up on this: \documentclass{article} \newcommand{\?}{\multicolumn{1}{c|}{\scriptsize0}} \begin{document} \begin{tabular}{cccccc|r} \? & \? & \? & \? & \? & 0 & 0 \\ \? & \? & \? & \? & \? & 1 & 1 \\ \cline{6-6} \? & \? & \? & \? & 1 & 0 & 2 \\ \? & \? & \? & \? ...


12

I think you wanted to write *{2}{c@{{}\mathrel{<}{}}}l instead of c*{2}{@{{}\mathrel{<}{}}l} which means having the last two columns left-aligned. In fact, the syntax for multiple columns with same alignment is *{<number of columns>}{<column alignment>} Also, since the < symbol is defined as \mathrel by default, you can ...



Only top voted, non community-wiki answers of a minimum length are eligible