This is probably best explained with an example. I have the following table, where the "A" cell spans two rows, and the "B" cell spans two columns.
\begin{table}[htdp]
\begin{tabular}{l|r|r}
\multirow{2}{*}{A} & \multicolumn{2}{c}{B} \\
& B1 & B2 \\
a & b1 & b2 \\
a & b1 & b2 \\
\end{tabular}
\end{table}
_ _ _ _ _ _ _ _ _ _ _ _
|A |_ _ _ _B_ _ _ _|
|_ _ _ _|_ _B1_ |_ _B2_ |
|a | b1| b2|
|a | b1| b2|
|a | b1| b2|
|_ _ _ _| _ _ _ |_ _ _ _|
I would like to center the text in the "A" cell, only. I would like to leave the rest of the column left-aligned. Giving:
_ _ _ _ _ _ _ _ _ _ _ _
| A |_ _ _ _B_ _ _ _|
|_ _ _ _|_ _B1_ |_ _B2_ |
|a | b1| b2|
|a | b1| b2|
|a | b1| b2|
|_ _ _ _| _ _ _ |_ _ _ _|
I'm sure this must be simple to do, but I can't seem to put my finger on it.
I think you need to do that with a fake \multicolumn:
\multicolumn{1}{c}{\multirow{2}{*}{A}} & \multicolumn{2}{c}B} \\
Inspiration from this FAQ.
I came across a similar problem, but had to use \multirow{specified width}{} instead of \multirow{*}{}. Nesting multirow inside a multicolumn does not work in this case.
I found \multirow{specified width}{\centering text} to work instead.
\multirow{2}{*}{\hfil A}
\hfil will automatically calculate the width of the cell and insert a half-width space
To insert a full cell-width space, which will right-justify a single cell, use \hfill.
There are also \vfil and \vfill analogues.
That is could be helpful for someone
\begin{tabular}{|c c | c|c|c|}
\hline
\multicolumn{2}{|c}{\multirow{2}{*}{Modulation}} & \multicolumn{3}{|c|}{M} \\
\cline{3-5}
& & 2 & 4 & 8 \\
\hline
\multirow{3}*{\hfil SNR=$\begin{cases} \\ \\ \end{cases}$} & STMA & xx dB & xx dB & xx dB\\
& QTMA & xx dB & xx dB & xx dB \\
& POSTMA & xx dB & xx dB & xx dB\\
\hline
\end{tabular}
Related
I built and ran Syntaxnet successfully on a set of 1400 tweets. I have difficulty in understanding what each parameter in the parsed file means. For example, I have the sentence:
Shoutout #Aetna for covering my doctor visit. Love you!
for which the parsed file contents are:
1 Shoutout _ NOUN NNP _ 9 nsubj _ _
2 # _ ADP IN _ 1 prep _ _
3 Aetna _ NOUN NNP _ 2 pobj _ _
4 for _ ADP IN _ 1 prep _ _
5 covering _ VERB VBG _ 4 pcomp _ _
6 my _ PRON PRP$ _ 8 poss _ _
7 doctor _ NOUN NN _ 8 nn _ _
8 visit. _ NOUN NN _ 5 dobj _ _
9 Love _ VERB VBP _ 0 ROOT _ _
10 you _ PRON PRP _ 9 dobj _ _
11 ! _ . . _ 9 punct _ _
What exactly do each of the columns mean? Why are there blanks and numbers other than the POS tags?
This type of format is called CoNLL Format. There are various versions available of it. The meaning of each column is described here
Lets say I have this grammar
E -> T+Ex | F
T -> T*Fy | w
F -> E | z | ε
Now I need to make it LL(1). I've been following the steps but the solution I came up with doesn't seem quite right.
Fist lets eliminate ε-productions
E -> T+Ex | F | T+x
T -> T*Fy | w | T*y
F -> E | z
Now we'll eliminate cycles
E -> T+Ex | T+x | z
T -> T*Fy | w | T*y
F -> T+Ex | T+x | z
No we'll eliminate immediate left recursion
E -> T+Ex | T+x | z
T -> wT'
T' -> *FyT' | *yT' | ε
F -> T+Ex | T+x | z
Finally we'll replace certain RHS productions where T occurred
E -> wT'+Ex | wT'+x | z
T -> wT'
T' -> *FyT' | *yT' | ε
F -> wT'+Ex | wT'+x | z
Now this doesn't seem to be LL(1) to me since the parse table generated by this will have multiple entries for several of the terminals. What do I seem to be missing?
I figured out how to do it, so out last step we have this configuration
E -> wT'+Ex | wT'+x | z
T -> wT'
T' -> *FyT' | *yT' | ε
F -> wT'+Ex | wT'+x | z
We now need to perform left-factorization to remove productions of the form
S -> aB | aC
And make them into the proper form
S -> aA
A -> B | C
Using this we can transform our grammar into
E -> wT'+E' | z
E' -> Ex | x
T -> wT'
T' -> *T'' | ε
T'' -> FyT' | yT'
F -> wT'+F' | z
F' -> Ex | x
Since F and F' are the same as E and E' we can just remove this production so we are left with.
E -> wT'+E' | z
E' -> Ex | x
T -> wT'
T' -> *T'' | ε
T'' -> EyT' | yT'
I am new to R markdown. I have a simple question about how to remove the automated equation numbering in the output PDF. Use the following codes for example:
\begin{align}
\sum_{i = 1}^{n} | (f + g )(x_i) - (f + g)(x_{i-1}) | &= \sum_{i = 1}^{n} | \{ f(x_i) + g(x_i) \} - \{ f(x_{i - 1} + g(x_{i-1}) \} |
\\ &\leq \sum_{i = 1}^{n} | f(x_i) - f(x_{i - 1} | + \sum_{i = 1}^{n} | g(x_i) - g(x_{i - 1})|
\\ &\leq V(f, P) + V(g, P)
\end{align}
It will automatically label the three lines of equations with (1), (2), (3). How do I suppress the numbering?
Thanks for your time!
I was actually looking up how to add numbering... so perfect info swap! Try:
$$
\begin{aligned}
\sum_{i = 1}^{n} | (f + g )(x_i) - (f + g)(x_{i-1}) | &= \sum_{i = 1}^{n} | \{ f(x_i) + g(x_i) \} - \{ f(x_{i - 1} + g(x_{i-1}) \} |
\\ &\leq \sum_{i = 1}^{n} | f(x_i) - f(x_{i - 1} | + \sum_{i = 1}^{n} | g(x_i) - g(x_{i - 1})|
\\ &\leq V(f, P) + V(g, P)
\end{aligned}
$$
This is more of a LaTeX thing than an RMarkdown thing: from my understanding, the $$ $$ isn't numbered, and the aligned environment is intended for use within other environments in order to display a single equation.
So, within the $$ $$ environment, you can use the aligned environment to display an equation, but it won't be numbered.
I missed the response from Werner earlier, but using align* works too. I guess the difference is the nuance in the initial intention.
(Also btw, this means if you use aligned within align, you get a block equation with only one number.)
I've written a typical evaluator for simple math expressions (arithmetic with some custom functions) in F#. While it seems to be working correctly, some expressions don't evaluate as expected, for example, these work fine:
eval "5+2" --> 7
eval "sqrt(25)^2" --> 25
eval "1/(sqrt(4))" --> 0.5
eval "1/(2^2+2)" --> 1/6 ~ 0.1666...
but these don't:
eval "1/(sqrt(4)+2)" --> evaluates to 1/sqrt(6) ~ 0.408...
eval "1/(sqrt 4 + 2)" --> will also evaluate to 1/sqrt(6)
eval "1/(-1+3)" --> evaluates to 1/(-4) ~ -0.25
the code works as follows, tokenization (string as input) -> to rev-polish-notation (RPN) -> evalRpn
I thought that the problem seems to occur somewhere with the unary functions (functions accepting one operator), these are the sqrt function and the negation (-) function. I don't really see what's going wrong in my code. Can someone maybe point out what I am missing here?
this is my implementation in F#
open System.Collections
open System.Collections.Generic
open System.Text.RegularExpressions
type Token =
| Num of float
| Plus
| Minus
| Star
| Hat
| Sqrt
| Slash
| Negative
| RParen
| LParen
let hasAny (list: Stack<'T>) =
list.Count <> 0
let tokenize (input:string) =
let tokens = new Stack<Token>()
let push tok = tokens.Push tok
let regex = new Regex(#"[0-9]+(\.+\d*)?|\+|\-|\*|\/|\^|\)|\(|pi|e|sqrt")
for x in regex.Matches(input.ToLower()) do
match x.Value with
| "+" -> push Plus
| "*" -> push Star
| "/" -> push Slash
| ")" -> push LParen
| "(" -> push RParen
| "^" -> push Hat
| "sqrt" -> push Sqrt
| "pi" -> push (Num System.Math.PI)
| "e" -> push (Num System.Math.E)
| "-" ->
if tokens |> hasAny then
match tokens.Peek() with
| LParen -> push Minus
| Num v -> push Minus
| _ -> push Negative
else
push Negative
| value -> push (Num (float value))
tokens.ToArray() |> Array.rev |> Array.toList
let isUnary = function
| Negative | Sqrt -> true
| _ -> false
let prec = function
| Hat -> 3
| Star | Slash -> 2
| Plus | Minus -> 1
| _ -> 0
let toRPN src =
let output = new ResizeArray<Token>()
let stack = new Stack<Token>()
let rec loop = function
| Num v::tokens ->
output.Add(Num v)
loop tokens
| RParen::tokens ->
stack.Push RParen
loop tokens
| LParen::tokens ->
while stack.Peek() <> RParen do
output.Add(stack.Pop())
stack.Pop() |> ignore // pop the "("
loop tokens
| op::tokens when op |> isUnary ->
stack.Push op
loop tokens
| op::tokens ->
if stack |> hasAny then
if prec(stack.Peek()) >= prec op then
output.Add(stack.Pop())
stack.Push op
loop tokens
| [] ->
output.AddRange(stack.ToArray())
output
(loop src).ToArray()
let (#) op tok =
match tok with
| Num v ->
match op with
| Sqrt -> Num (sqrt v)
| Negative -> Num (v * -1.0)
| _ -> failwith "input error"
| _ -> failwith "input error"
let (##) op toks =
match toks with
| Num v,Num u ->
match op with
| Plus -> Num(v + u)
| Minus -> Num(v - u)
| Star -> Num(v * u)
| Slash -> Num(u / v)
| Hat -> Num(u ** v)
| _ -> failwith "input error"
| _ -> failwith "inpur error"
let evalRPN src =
let stack = new Stack<Token>()
let rec loop = function
| Num v::tokens ->
stack.Push(Num v)
loop tokens
| op::tokens when op |> isUnary ->
let result = op # stack.Pop()
stack.Push result
loop tokens
| op::tokens ->
let result = op ## (stack.Pop(),stack.Pop())
stack.Push result
loop tokens
| [] -> stack
if loop src |> hasAny then
match stack.Pop() with
| Num v -> v
| _ -> failwith "input error"
else failwith "input error"
let eval input =
input |> (tokenize >> toRPN >> Array.toList >> evalRPN)
Before answering your specific question, did you notice you have another bug? Try eval "2-4" you get 2.0 instead of -2.0.
That's probably because along these lines:
match op with
| Plus -> Num(v + u)
| Minus -> Num(v - u)
| Star -> Num(v * u)
| Slash -> Num(u / v)
| Hat -> Num(u ** v)
u and v are swapped, in commutative operations you don't notice the difference, so just revert them to u -v.
Now regarding the bug you mentioned, the cause seems obvious to me, by looking at your code you missed the precedence of those unary operations:
let prec = function
| Hat -> 3
| Star | Slash -> 2
| Plus | Minus -> 1
| _ -> 0
I tried adding them this way:
let prec = function
| Negative -> 5
| Sqrt -> 4
| Hat -> 3
| Star | Slash -> 2
| Plus | Minus -> 1
| _ -> 0
And now it seems to be fine.
Edit: meh, seems I was late, Gustavo posted the answer while I was wondering about the parentheses. Oh well.
Unary operators have the wrong precedence. Add the primary case | a when isUnary a -> 4 to prec.
The names of LParen and RParen are consistently swapped throughout the code. ( maps to RParen and ) to LParen!
It runs all tests from the question properly for me, given the appropriate precedence, but I haven't checked the code for correctness.
Is there a way to do a match within a match in F#? I've noticed that you can do one tailed on another like so...
match L.Head with
| null -> []
| _ -> match N with
| 1 -> [L.Head]
| _ -> []
But is there a way to do it so that a match, ending with a _ can be placed in the MIDDLE of another match? This seems to give a bug... is there a better way to do this, should you need it for your logic? EX:
match A with
| 0 -> match B with
| 1 -> 1
| _ -> 0
| _ -> 2
Why not use match on a tuple -
match (A,B) with
|0,1 -> 1
|0,_ -> 0
|_, -> 2
Not sure whether it was possible 7 years ago, but now you can use struct to reduce allocations:
match struct (A, B) with
| 0, 1 -> 1
| 0, _ -> 0
| _ -> 2
Old answer creates instance of System.Tuple`2, while this creates instance of System.ValueTuple`2
Decompilation